diff --git a/minidom/CHANGELOG.md b/minidom/CHANGELOG.md index 1de86464d4bd8c1a0f251dfe170937826f43ef77..d3ce5e7e9a86d95aa641b6d443c21279da33533b 100644 --- a/minidom/CHANGELOG.md +++ b/minidom/CHANGELOG.md @@ -1,3 +1,7 @@ +Version NEXT: + * Changes + * Almost make the whole crate `no_std`, only `std::io` is still remaining. + Version 0.16, released 2024-07-23: * Breaking * Element comparison returns unequal when number of nodes is unequal. diff --git a/minidom/src/convert.rs b/minidom/src/convert.rs index d113f151749f75eedfaa7425b6db0324f874ea85..3ca5a292a9ea87c11f2ab9566381c07b4ac38748 100644 --- a/minidom/src/convert.rs +++ b/minidom/src/convert.rs @@ -7,6 +7,8 @@ //! A module which exports a few traits for converting types to elements and attributes. +use alloc::string::String; + /// A trait for types which can be converted to an attribute value. pub trait IntoAttributeValue { /// Turns this into an attribute string, or None if it shouldn't be added. @@ -17,7 +19,7 @@ macro_rules! impl_into_attribute_value { ($t:ty) => { impl IntoAttributeValue for $t { fn into_attribute_value(self) -> Option { - Some(format!("{}", self)) + Some(self.to_string()) } } }; diff --git a/minidom/src/element.rs b/minidom/src/element.rs index 425dd4c30ef4242e1c03ef1fa449def8c574cd6d..21f96b1c75a240a4b2a79fc76fb0c71c9909198a 100644 --- a/minidom/src/element.rs +++ b/minidom/src/element.rs @@ -19,10 +19,10 @@ use crate::node::Node; use crate::prefixes::{Namespace, Prefix, Prefixes}; use crate::tree_builder::TreeBuilder; -use alloc::{ - borrow::Cow, - collections::btree_map::{self, BTreeMap}, -}; +use alloc::borrow::Cow; +use alloc::collections::btree_map::{self, BTreeMap}; +use alloc::string::String; +use alloc::vec::Vec; use core::slice; use core::str::FromStr; @@ -360,7 +360,7 @@ impl Element { reader: R, prefixes: P, ) -> Result { - let mut tree_builder = TreeBuilder::new().with_prefixes_stack(vec![prefixes.into()]); + let mut tree_builder = TreeBuilder::new().with_prefixes_stack([prefixes.into()].into()); let mut driver = RawReader::new(reader); while let Some(event) = driver.read()? { tree_builder.process_event(event)?; @@ -964,7 +964,7 @@ mod tests { "name".to_owned(), "namespace".to_owned(), (None, "namespace".to_owned()), - BTreeMap::from_iter(vec![("name".to_string(), "value".to_string())].into_iter()), + BTreeMap::from_iter([("name".to_string(), "value".to_string())].into_iter()), Vec::new(), ); diff --git a/minidom/src/node.rs b/minidom/src/node.rs index 8fd2a6c6ff7dfb565cde12793f7596e02b4d9668..e5496eeff33dfe5a327d29bfb25b908f0d68260c 100644 --- a/minidom/src/node.rs +++ b/minidom/src/node.rs @@ -10,6 +10,7 @@ use crate::element::{Element, ElementBuilder, ItemWriter}; use crate::error::Result; +use alloc::string::String; use rxml::writer::Item; diff --git a/minidom/src/prefixes.rs b/minidom/src/prefixes.rs index 212d73ce38d1ec67b849dce698a54763185f9a57..2d82b2ba68f9b77593f54f9c4ac845c498b2596e 100644 --- a/minidom/src/prefixes.rs +++ b/minidom/src/prefixes.rs @@ -7,8 +7,9 @@ // 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 alloc::collections::BTreeMap; +use alloc::string::String; use core::fmt; -use std::collections::BTreeMap; pub type Prefix = Option; pub type Namespace = String; @@ -23,15 +24,11 @@ impl fmt::Debug for Prefixes { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Prefixes(")?; for (prefix, namespace) in &self.prefixes { - write!( - f, - "xmlns{}={:?} ", - match prefix { - None => String::new(), - Some(prefix) => format!(":{}", prefix), - }, - namespace - )?; + if let Some(prefix) = prefix { + write!(f, "xmlns:{prefix}={namespace:?} ")?; + } else { + write!(f, "xmlns={namespace:?} ")?; + } } write!(f, ")") } diff --git a/minidom/src/tests.rs b/minidom/src/tests.rs index c7d7934699adb87d90b6da7038b72e0a83f27c9b..476291cbfca2cd731dcaee2d061547ac8b08ba66 100644 --- a/minidom/src/tests.rs +++ b/minidom/src/tests.rs @@ -12,6 +12,9 @@ use crate::element::Element; use crate::error::Error; +use alloc::format; +use alloc::string::String; +use alloc::vec::Vec; const TEST_STRING: &'static [u8] = br#"meownya"#; @@ -82,7 +85,7 @@ fn test_real_data() { .append(body) .append(correction) .build(); - let stream = Element::builder("stream", "http://etherx.jabber.org/streams") + let _stream = Element::builder("stream", "http://etherx.jabber.org/streams") .prefix( Some(String::from("stream")), "http://etherx.jabber.org/streams", @@ -92,7 +95,6 @@ fn test_real_data() { .unwrap() .append(message) .build(); - println!("{}", String::from(&stream)); let jid = Element::builder("jid", "urn:xmpp:presence:0").build(); let nick = Element::builder("nick", "urn:xmpp:presence:0").build(); @@ -119,7 +121,7 @@ fn test_real_data() { let iq = Element::builder("iq", "jabber:client") .append(pubsub) .build(); - let stream = Element::builder("stream", "http://etherx.jabber.org/streams") + let _stream = Element::builder("stream", "http://etherx.jabber.org/streams") .prefix( Some(String::from("stream")), "http://etherx.jabber.org/streams", @@ -129,8 +131,6 @@ fn test_real_data() { .unwrap() .append(iq) .build(); - - println!("{}", String::from(&stream)); } #[test] diff --git a/minidom/src/tree_builder.rs b/minidom/src/tree_builder.rs index 73f60c99ad3bd115a6ec7ddedc1306c84c66f441..4a3e11e8570da1febaa5c6f17862f248fbeae733 100644 --- a/minidom/src/tree_builder.rs +++ b/minidom/src/tree_builder.rs @@ -4,8 +4,11 @@ use crate::prefixes::{Prefix, Prefixes}; use crate::{Element, Error}; +use alloc::collections::BTreeMap; +use alloc::format; +use alloc::string::String; +use alloc::vec::Vec; use rxml::RawEvent; -use std::collections::BTreeMap; /// Tree-building parser state pub struct TreeBuilder { @@ -30,8 +33,8 @@ impl TreeBuilder { pub fn new() -> Self { TreeBuilder { next_tag: None, - stack: vec![], - prefixes_stack: vec![], + stack: Vec::new(), + prefixes_stack: Vec::new(), root: None, } } @@ -143,8 +146,7 @@ impl TreeBuilder { .lookup_prefix(&prefix.map(|prefix| prefix.as_str().to_owned())) .ok_or(Error::MissingNamespace)? .to_owned(); - let el = - Element::new(name.as_str().to_owned(), namespace, prefixes, attrs, vec![]); + let el = Element::new(name.to_owned(), namespace, prefixes, attrs, Vec::new()); self.stack.push(el); } }