minidom: Replace std stuff with alloc/core stuff

This commit is contained in:
xmppftw xmppftw 2024-12-19 19:38:21 +01:00 • committed by Emmanuel Gil Peyrot
commit 3ebc30c7ab
6 changed files with 23 additions and 16 deletions

View file

@ -22,3 +22,7 @@ gitlab = { repository = "xmpp-rs/xmpp-rs" }
[dependencies] [dependencies]
rxml = { version = "0.12.0", default-features = false, features = ["compact_str"] } rxml = { version = "0.12.0", default-features = false, features = ["compact_str"] }
[features]
default = [ "std" ]
std = []

View file

@ -40,7 +40,7 @@ impl_into_attribute_values!(
i32, i32,
i16, i16,
i8, i8,
::std::net::IpAddr ::core::net::IpAddr
); );
impl IntoAttributeValue for String { impl IntoAttributeValue for String {
@ -70,8 +70,8 @@ impl<T: IntoAttributeValue> IntoAttributeValue for Option<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::IntoAttributeValue; use super::IntoAttributeValue;
use std::net::IpAddr; use core::net::IpAddr;
use std::str::FromStr; use core::str::FromStr;
#[test] #[test]
fn test_into_attribute_value_on_ints() { fn test_into_attribute_value_on_ints() {

View file

@ -19,18 +19,19 @@ use crate::node::Node;
use crate::prefixes::{Namespace, Prefix, Prefixes}; use crate::prefixes::{Namespace, Prefix, Prefixes};
use crate::tree_builder::TreeBuilder; use crate::tree_builder::TreeBuilder;
use std::borrow::Cow; use alloc::{
use std::collections::{btree_map, BTreeMap}; borrow::Cow,
collections::btree_map::{self, BTreeMap},
};
use core::slice;
use core::str::FromStr;
use std::io::{self, BufRead, Write}; use std::io::{self, BufRead, Write};
use std::str;
use rxml::writer::{Encoder, Item, TrackNamespace}; use rxml::writer::{Encoder, Item, TrackNamespace};
use rxml::{Namespace as RxmlNamespace, RawReader, XmlVersion}; use rxml::{Namespace as RxmlNamespace, RawReader, XmlVersion};
use std::str::FromStr;
use std::slice;
fn encode_and_write<W: Write, T: rxml::writer::TrackNamespace>( fn encode_and_write<W: Write, T: rxml::writer::TrackNamespace>(
item: Item<'_>, item: Item<'_>,
enc: &mut Encoder<T>, enc: &mut Encoder<T>,
@ -802,7 +803,7 @@ impl<'a> Iterator for ChildrenMut<'a> {
/// An iterator over references to child elements of an `Element`. /// An iterator over references to child elements of an `Element`.
pub struct ContentsAsChildren<'a> { pub struct ContentsAsChildren<'a> {
iter: std::vec::Drain<'a, Node>, iter: alloc::vec::Drain<'a, Node>,
} }
impl<'a> Iterator for ContentsAsChildren<'a> { impl<'a> Iterator for ContentsAsChildren<'a> {

View file

@ -13,7 +13,7 @@
use std::io; use std::io;
use std::error::Error as StdError; use core::{error::Error as StdError, fmt};
/// Our main error type. /// Our main error type.
#[derive(Debug)] #[derive(Debug)]
@ -65,8 +65,8 @@ impl From<io::Error> for Error {
} }
} }
impl std::fmt::Display for Error { impl fmt::Display for Error {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
Error::XmlError(e) => write!(fmt, "XML error: {}", e), Error::XmlError(e) => write!(fmt, "XML error: {}", e),
Error::Io(e) => write!(fmt, "I/O error: {}", e), Error::Io(e) => write!(fmt, "I/O error: {}", e),
@ -93,4 +93,4 @@ impl From<rxml::strings::Error> for Error {
} }
/// Our simplified Result type. /// Our simplified Result type.
pub type Result<T> = ::std::result::Result<T, Error>; pub type Result<T> = ::core::result::Result<T, Error>;

View file

@ -76,6 +76,8 @@
//! minidom = "*" //! minidom = "*"
//! ``` //! ```
extern crate alloc;
pub mod convert; pub mod convert;
pub mod element; pub mod element;
pub mod error; pub mod error;

View file

@ -7,8 +7,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use core::fmt;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::fmt;
pub type Prefix = Option<String>; pub type Prefix = Option<String>;
pub type Namespace = String; pub type Namespace = String;