From 3ebc30c7ab92027754dc999730fa5d24505aa1a5 Mon Sep 17 00:00:00 2001 From: xmppftw Date: Thu, 19 Dec 2024 19:38:21 +0100 Subject: [PATCH] minidom: Replace std stuff with alloc/core stuff --- 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(-) diff --git a/minidom/Cargo.toml b/minidom/Cargo.toml index c142ba63db846ac84dacf5351a37f3cb64928312..4fecb4e8e65a8b34c5778834a695146a599c3eae 100644 --- a/minidom/Cargo.toml +++ b/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 = [] diff --git a/minidom/src/convert.rs b/minidom/src/convert.rs index 81328b1d3712823b47c71ce10e9f5565f4dd2366..3db89720b7c1c243ad49bb118adf08e06572278c 100644 --- a/minidom/src/convert.rs +++ b/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 IntoAttributeValue for Option { #[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() { diff --git a/minidom/src/element.rs b/minidom/src/element.rs index 61fb43cb118499f2eb246d4bf6b52f4f2a9dd604..f67d7fc6bb76a6b0c7ba34eca83fc06376df9837 100644 --- a/minidom/src/element.rs +++ b/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( item: Item<'_>, enc: &mut Encoder, @@ -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> { diff --git a/minidom/src/error.rs b/minidom/src/error.rs index b0265c62b3172b8ff849786cd25599cb89438bf2..d3cab837c9a6980e3906067fa5b02b92470fe7c3 100644 --- a/minidom/src/error.rs +++ b/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 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 for Error { } /// Our simplified Result type. -pub type Result = ::std::result::Result; +pub type Result = ::core::result::Result; diff --git a/minidom/src/lib.rs b/minidom/src/lib.rs index 11793608f582757cbd0d00e954cd663200357c16..d25934b609ecec1a55d70a184d8dcc2deef243a0 100644 --- a/minidom/src/lib.rs +++ b/minidom/src/lib.rs @@ -76,6 +76,8 @@ //! minidom = "*" //! ``` +extern crate alloc; + pub mod convert; pub mod element; pub mod error; diff --git a/minidom/src/prefixes.rs b/minidom/src/prefixes.rs index 909cb7ab8f2d7be917c5b7ef8316533086909679..212d73ce38d1ec67b849dce698a54763185f9a57 100644 --- a/minidom/src/prefixes.rs +++ b/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; pub type Namespace = String;