minidom: Replace std stuff with alloc/core stuff

xmppftw created

Change summary

minidom/Cargo.toml      |  4 ++++
minidom/src/convert.rs  |  6 +++---
minidom/src/element.rs  | 17 +++++++++--------
minidom/src/error.rs    |  8 ++++----
minidom/src/lib.rs      |  2 ++
minidom/src/prefixes.rs |  2 +-
6 files changed, 23 insertions(+), 16 deletions(-)

Detailed changes

minidom/Cargo.toml 🔗

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

minidom/src/convert.rs 🔗

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

minidom/src/element.rs 🔗

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

minidom/src/error.rs 🔗

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

minidom/src/lib.rs 🔗

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

minidom/src/prefixes.rs 🔗

@@ -7,8 +7,8 @@
 // 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/.
 
+use core::fmt;
 use std::collections::BTreeMap;
-use std::fmt;
 
 pub type Prefix = Option<String>;
 pub type Namespace = String;