xmpp-parsers: Don’t use anything from std

Emmanuel Gil Peyrot created

The remaining two were core::str::FromStr and
alloc::collections::BTreeMap.

Note that this doesn’t allow us to be no_std yet.

skip-changelog: This isn’t in any way user-visible, except that some
structs are now slightly smaller.

Change summary

parsers/src/cert_management.rs |  2 +-
parsers/src/delay.rs           |  2 +-
parsers/src/fast.rs            |  2 +-
parsers/src/ibr.rs             | 10 +++++-----
parsers/src/idle.rs            |  2 +-
parsers/src/jingle_s5b.rs      |  2 +-
parsers/src/message.rs         |  2 +-
parsers/src/muc/muc.rs         |  2 +-
parsers/src/openpgp.rs         |  2 +-
parsers/src/pubsub/owner.rs    |  2 +-
parsers/src/roster.rs          |  2 +-
parsers/src/sasl.rs            |  2 +-
parsers/src/time.rs            |  2 +-
parsers/src/tune.rs            |  2 +-
parsers/src/util/macros.rs     | 12 ++++++------
parsers/src/vcard.rs           |  2 +-
parsers/src/vcard_update.rs    |  2 +-
parsers/src/xhtml.rs           | 12 ++++++------
18 files changed, 32 insertions(+), 32 deletions(-)

Detailed changes

parsers/src/cert_management.rs 🔗

@@ -125,8 +125,8 @@ impl IqSetPayload for Revoke {}
 mod tests {
     use super::*;
     use crate::ns;
+    use core::str::FromStr;
     use minidom::Element;
-    use std::str::FromStr;
 
     #[cfg(target_pointer_width = "32")]
     #[test]

parsers/src/delay.rs 🔗

@@ -35,9 +35,9 @@ impl PresencePayload for Delay {}
 #[cfg(test)]
 mod tests {
     use super::*;
+    use core::str::FromStr;
     use jid::BareJid;
     use minidom::Element;
-    use std::str::FromStr;
     use xso::error::{Error, FromElementError};
 
     #[cfg(target_pointer_width = "32")]

parsers/src/fast.rs 🔗

@@ -71,8 +71,8 @@ pub struct Token {
 #[cfg(test)]
 mod tests {
     use super::*;
+    use core::str::FromStr;
     use minidom::Element;
-    use std::str::FromStr;
 
     #[test]
     fn test_simple() {

parsers/src/ibr.rs 🔗

@@ -7,8 +7,8 @@
 use crate::data_forms::DataForm;
 use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload};
 use crate::ns;
+use alloc::collections::BTreeMap;
 use minidom::Element;
-use std::collections::HashMap;
 use xso::error::{Error, FromElementError};
 
 /// Query for registering against a service.
@@ -16,7 +16,7 @@ use xso::error::{Error, FromElementError};
 pub struct Query {
     /// Deprecated fixed list of possible fields to fill before the user can
     /// register.
-    pub fields: HashMap<String, String>,
+    pub fields: BTreeMap<String, String>,
 
     /// Whether this account is already registered.
     pub registered: bool,
@@ -41,7 +41,7 @@ impl TryFrom<Element> for Query {
         check_self!(elem, "query", REGISTER, "IBR query");
         let mut query = Query {
             registered: false,
-            fields: HashMap::new(),
+            fields: BTreeMap::new(),
             remove: false,
             form: None,
         };
@@ -119,13 +119,13 @@ mod tests {
     #[cfg(target_pointer_width = "32")]
     #[test]
     fn test_size() {
-        assert_size!(Query, 88);
+        assert_size!(Query, 68);
     }
 
     #[cfg(target_pointer_width = "64")]
     #[test]
     fn test_size() {
-        assert_size!(Query, 160);
+        assert_size!(Query, 136);
     }
 
     #[test]

parsers/src/idle.rs 🔗

@@ -24,8 +24,8 @@ impl PresencePayload for Idle {}
 #[cfg(test)]
 mod tests {
     use super::*;
+    use core::str::FromStr;
     use minidom::Element;
-    use std::str::FromStr;
     use xso::error::{Error, FromElementError};
 
     #[test]

parsers/src/jingle_s5b.rs 🔗

@@ -309,7 +309,7 @@ impl ::xso::AsXml for Transport {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use std::str::FromStr;
+    use core::str::FromStr;
 
     #[cfg(target_pointer_width = "32")]
     #[test]

parsers/src/message.rs 🔗

@@ -402,7 +402,7 @@ impl ::xso::AsXml for Message {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use std::str::FromStr;
+    use core::str::FromStr;
 
     #[cfg(target_pointer_width = "32")]
     #[test]

parsers/src/muc/muc.rs 🔗

@@ -100,8 +100,8 @@ impl Muc {
 #[cfg(test)]
 mod tests {
     use super::*;
+    use core::str::FromStr;
     use minidom::Element;
-    use std::str::FromStr;
     use xso::error::{Error, FromElementError};
 
     #[test]

parsers/src/openpgp.rs 🔗

@@ -67,8 +67,8 @@ mod tests {
         pubsub::{Item as PubSubItem, Publish},
         Item, NodeName,
     };
+    use core::str::FromStr;
     use minidom::Element;
-    use std::str::FromStr;
 
     #[test]
     fn pubsub_publish_pubkey_data() {

parsers/src/pubsub/owner.rs 🔗

@@ -192,8 +192,8 @@ impl From<PubSubOwner> for Element {
 mod tests {
     use super::*;
     use crate::data_forms::{DataFormType, Field, FieldType};
+    use core::str::FromStr;
     use jid::BareJid;
-    use std::str::FromStr;
 
     #[test]
     fn affiliations() {

parsers/src/roster.rs 🔗

@@ -97,8 +97,8 @@ impl IqResultPayload for Roster {}
 #[cfg(test)]
 mod tests {
     use super::*;
+    use core::str::FromStr;
     use minidom::Element;
-    use std::str::FromStr;
     use xso::error::{Error, FromElementError};
 
     #[cfg(target_pointer_width = "32")]

parsers/src/sasl.rs 🔗

@@ -7,7 +7,7 @@
 use xso::{text::Base64, AsXml, FromXml};
 
 use crate::ns;
-use std::collections::BTreeMap;
+use alloc::collections::BTreeMap;
 
 generate_attribute!(
     /// The list of available SASL mechanisms.

parsers/src/time.rs 🔗

@@ -10,8 +10,8 @@ use crate::date::DateTime;
 use crate::iq::{IqGetPayload, IqResultPayload};
 use crate::ns;
 use chrono::FixedOffset;
+use core::str::FromStr;
 use minidom::Element;
-use std::str::FromStr;
 use xso::error::{Error, FromElementError};
 
 /// An entity time query.

parsers/src/tune.rs 🔗

@@ -117,8 +117,8 @@ impl Tune {
 #[cfg(test)]
 mod tests {
     use super::*;
+    use core::str::FromStr;
     use minidom::Element;
-    use std::str::FromStr;
 
     #[cfg(target_pointer_width = "32")]
     #[test]

parsers/src/util/macros.rs 🔗

@@ -73,7 +73,7 @@ macro_rules! generate_attribute {
                 $a
             ),+
         }
-        impl ::std::str::FromStr for $elem {
+        impl ::core::str::FromStr for $elem {
             type Err = xso::error::Error;
             fn from_str(s: &str) -> Result<$elem, xso::error::Error> {
                 Ok(match s {
@@ -120,7 +120,7 @@ macro_rules! generate_attribute {
                 $a
             ),+
         }
-        impl ::std::str::FromStr for $elem {
+        impl ::core::str::FromStr for $elem {
             type Err = xso::error::Error;
             fn from_str(s: &str) -> Result<$elem, xso::error::Error> {
                 Ok(match s {
@@ -173,7 +173,7 @@ macro_rules! generate_attribute {
             /// Value when absent.
             None,
         }
-        impl ::std::str::FromStr for $elem {
+        impl ::core::str::FromStr for $elem {
             type Err = xso::error::Error;
             fn from_str(s: &str) -> Result<Self, xso::error::Error> {
                 Ok(match s {
@@ -218,7 +218,7 @@ macro_rules! generate_attribute {
         $(#[$meta])*
         #[derive(Debug, Clone, PartialEq)]
         pub struct $elem(pub $type);
-        impl ::std::str::FromStr for $elem {
+        impl ::core::str::FromStr for $elem {
             type Err = xso::error::Error;
             fn from_str(s: &str) -> Result<Self, xso::error::Error> {
                 Ok($elem($type::from_str(s).map_err(xso::error::Error::text_parse_error)?))
@@ -382,7 +382,7 @@ macro_rules! generate_id {
         $(#[$meta])*
         #[derive(Debug, Clone, PartialEq, Eq, Hash)]
         pub struct $elem(pub String);
-        impl ::std::str::FromStr for $elem {
+        impl ::core::str::FromStr for $elem {
             type Err = xso::error::Error;
             fn from_str(s: &str) -> Result<$elem, xso::error::Error> {
                 // TODO: add a way to parse that differently when needed.
@@ -410,7 +410,7 @@ macro_rules! generate_id {
 macro_rules! generate_elem_id {
     ($(#[$meta:meta])* $elem:ident, $name:literal, $ns:ident) => (
         generate_elem_id!($(#[$meta])* $elem, $name, $ns, String);
-        impl ::std::str::FromStr for $elem {
+        impl ::core::str::FromStr for $elem {
             type Err = xso::error::Error;
             fn from_str(s: &str) -> Result<$elem, xso::error::Error> {
                 // TODO: add a way to parse that differently when needed.

parsers/src/vcard.rs 🔗

@@ -73,7 +73,7 @@ impl IqResultPayload for VCard {}
 #[cfg(test)]
 mod tests {
     use super::*;
-    use std::str::FromStr;
+    use core::str::FromStr;
 
     #[cfg(target_pointer_width = "32")]
     #[test]

parsers/src/vcard_update.rs 🔗

@@ -37,8 +37,8 @@ pub struct Photo {
 #[cfg(test)]
 mod tests {
     use super::*;
+    use core::str::FromStr;
     use minidom::Element;
-    use std::str::FromStr;
 
     #[test]
     fn test_vcard_update() {

parsers/src/xhtml.rs 🔗

@@ -6,8 +6,8 @@
 
 use crate::message::MessagePayload;
 use crate::ns;
+use alloc::collections::BTreeMap;
 use minidom::{Element, Node};
-use std::collections::HashMap;
 use xso::error::{Error, FromElementError};
 
 // TODO: Use a proper lang type.
@@ -17,7 +17,7 @@ type Lang = String;
 #[derive(Debug, Clone)]
 pub struct XhtmlIm {
     /// Map of language to body element.
-    bodies: HashMap<Lang, Body>,
+    bodies: BTreeMap<Lang, Body>,
 }
 
 impl XhtmlIm {
@@ -41,7 +41,7 @@ impl XhtmlIm {
 
     /// Removes all unknown elements.
     fn flatten(self) -> XhtmlIm {
-        let mut bodies = HashMap::new();
+        let mut bodies = BTreeMap::new();
         for (lang, body) in self.bodies {
             let children = body.children.into_iter().fold(vec![], |mut acc, child| {
                 match child {
@@ -66,7 +66,7 @@ impl TryFrom<Element> for XhtmlIm {
         check_self!(elem, "html", XHTML_IM);
         check_no_attributes!(elem, "html");
 
-        let mut bodies = HashMap::new();
+        let mut bodies = BTreeMap::new();
         for child in elem.children() {
             if child.is("body", ns::XHTML) {
                 let child = child.clone();
@@ -504,7 +504,7 @@ mod tests {
     #[cfg(target_pointer_width = "32")]
     #[test]
     fn test_size() {
-        assert_size!(XhtmlIm, 32);
+        assert_size!(XhtmlIm, 12);
         assert_size!(Child, 48);
         assert_size!(Tag, 48);
     }
@@ -512,7 +512,7 @@ mod tests {
     #[cfg(target_pointer_width = "64")]
     #[test]
     fn test_size() {
-        assert_size!(XhtmlIm, 48);
+        assert_size!(XhtmlIm, 24);
         assert_size!(Child, 96);
         assert_size!(Tag, 96);
     }