xmpp-parsers: Don’t use anything from std

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.
This commit is contained in:
Emmanuel Gil Peyrot 2025-01-25 20:35:47 +01:00 committed by Jonas Schäfer
commit 0adca163f8
18 changed files with 32 additions and 32 deletions

View file

@ -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]

View file

@ -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")]

View file

@ -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() {

View file

@ -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]

View file

@ -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]

View file

@ -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]

View file

@ -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]

View file

@ -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]

View file

@ -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() {

View file

@ -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() {

View file

@ -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")]

View file

@ -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.

View file

@ -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.

View file

@ -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]

View file

@ -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.

View file

@ -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]

View file

@ -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() {

View file

@ -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);
}