From 1ce2f894aa59e21cc5b048ee9a168a947526e693 Mon Sep 17 00:00:00 2001 From: xmppftw Date: Thu, 19 Dec 2024 19:34:10 +0100 Subject: [PATCH] tokio_xmpp: Replace std stuff with alloc/core stuff --- tokio-xmpp/examples/keep_connection.rs | 4 ++-- tokio-xmpp/src/client/login.rs | 4 ++-- tokio-xmpp/src/client/stream.rs | 3 +-- tokio-xmpp/src/connect/dns.rs | 6 +++--- tokio-xmpp/src/connect/mod.rs | 4 ++-- tokio-xmpp/src/connect/starttls.rs | 7 +++---- tokio-xmpp/src/connect/tcp.rs | 2 +- tokio-xmpp/src/error.rs | 5 +---- tokio-xmpp/src/lib.rs | 2 ++ tokio-xmpp/src/xmlstream/common.rs | 12 +++++++----- tokio-xmpp/src/xmlstream/mod.rs | 4 ++-- tokio-xmpp/src/xmlstream/tests.rs | 2 +- 12 files changed, 27 insertions(+), 28 deletions(-) diff --git a/tokio-xmpp/examples/keep_connection.rs b/tokio-xmpp/examples/keep_connection.rs index a37fda19ea1a70d9500c756437cd086a0f832e59..bb64fc4d1fcf50849368e83f482b8c17b0815114 100644 --- a/tokio-xmpp/examples/keep_connection.rs +++ b/tokio-xmpp/examples/keep_connection.rs @@ -10,10 +10,10 @@ //! as good as it can, transparently reconnecting on interruptions of the TCP //! stream. +use core::str::FromStr; +use core::time::Duration; use std::env::args; use std::process::exit; -use std::str::FromStr; -use std::time::Duration; use rand::{thread_rng, Rng}; diff --git a/tokio-xmpp/src/client/login.rs b/tokio-xmpp/src/client/login.rs index a1bc87edcc5e5caecc6af5138579b8ddf44f9c81..cf3a269c1791e36dea3c5487094842515c7137ae 100644 --- a/tokio-xmpp/src/client/login.rs +++ b/tokio-xmpp/src/client/login.rs @@ -1,12 +1,12 @@ +use alloc::borrow::Cow; +use core::str::FromStr; use futures::{SinkExt, StreamExt}; use sasl::client::mechanisms::{Anonymous, Plain, Scram}; use sasl::client::Mechanism; use sasl::common::scram::{Sha1, Sha256}; use sasl::common::Credentials; -use std::borrow::Cow; use std::collections::HashSet; use std::io; -use std::str::FromStr; use tokio::io::{AsyncBufRead, AsyncWrite}; use xmpp_parsers::{ jid::Jid, diff --git a/tokio-xmpp/src/client/stream.rs b/tokio-xmpp/src/client/stream.rs index 54ff8c55837d6a9f6b41d2832e0fd17076e2c1c5..c585276b4394793aca253abfd61e9584ffe19205 100644 --- a/tokio-xmpp/src/client/stream.rs +++ b/tokio-xmpp/src/client/stream.rs @@ -4,9 +4,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::{pin::Pin, task::Context}; use futures::{ready, task::Poll, Stream}; -use std::pin::Pin; -use std::task::Context; use crate::{ client::Client, diff --git a/tokio-xmpp/src/connect/dns.rs b/tokio-xmpp/src/connect/dns.rs index df896d66e70d07d445bb869f47c625afbe2005f8..dc6bf7a386026497b64cf7f8f37a95090ff5c84c 100644 --- a/tokio-xmpp/src/connect/dns.rs +++ b/tokio-xmpp/src/connect/dns.rs @@ -1,3 +1,4 @@ +use core::{fmt, net::SocketAddr}; #[cfg(feature = "dns")] use futures::{future::select_ok, FutureExt}; #[cfg(feature = "dns")] @@ -6,7 +7,6 @@ use hickory_resolver::{ }; #[cfg(feature = "dns")] use log::debug; -use std::net::SocketAddr; use tokio::net::TcpStream; use crate::Error; @@ -43,8 +43,8 @@ pub enum DnsConfig { }, } -impl std::fmt::Display for DnsConfig { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for DnsConfig { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { #[cfg(feature = "dns")] Self::UseSrv { host, .. } => write!(f, "{}", host), diff --git a/tokio-xmpp/src/connect/mod.rs b/tokio-xmpp/src/connect/mod.rs index 0fba5b0d4f637f62d4e407cf48f7505aabd2d3d2..240d915317dea3ee418b10af32269e1333f32411 100644 --- a/tokio-xmpp/src/connect/mod.rs +++ b/tokio-xmpp/src/connect/mod.rs @@ -25,7 +25,7 @@ pub trait AsyncReadAndWrite: AsyncBufRead + AsyncWrite + Unpin + Send {} impl AsyncReadAndWrite for T {} /// Trait that must be extended by the implementation of ServerConnector -pub trait ServerConnectorError: std::error::Error + Sync + Send {} +pub trait ServerConnectorError: core::error::Error + Sync + Send {} /// Trait called to connect to an XMPP server, perhaps called multiple times pub trait ServerConnector: Clone + core::fmt::Debug + Send + Unpin + 'static { @@ -37,7 +37,7 @@ pub trait ServerConnector: Clone + core::fmt::Debug + Send + Unpin + 'static { jid: &Jid, ns: &'static str, timeouts: Timeouts, - ) -> impl std::future::Future< + ) -> impl core::future::Future< Output = Result<(PendingFeaturesRecv, ChannelBinding), Error>, > + Send; } diff --git a/tokio-xmpp/src/connect/starttls.rs b/tokio-xmpp/src/connect/starttls.rs index 067c7e24d8a865460393fe9428504461bd01a910..a1fae23b208e7d211634b50371e32bf0b1a664e1 100644 --- a/tokio-xmpp/src/connect/starttls.rs +++ b/tokio-xmpp/src/connect/starttls.rs @@ -1,10 +1,9 @@ //! `starttls::ServerConfig` provides a `ServerConnector` for starttls connections +use alloc::borrow::Cow; +use core::{error::Error as StdError, fmt}; #[cfg(feature = "tls-native")] use native_tls::Error as TlsError; -use std::borrow::Cow; -use std::error::Error as StdError; -use std::fmt; use std::io; use std::os::fd::AsRawFd; #[cfg(all(feature = "tls-rust", not(feature = "tls-native")))] @@ -16,7 +15,7 @@ use futures::{sink::SinkExt, stream::StreamExt}; #[cfg(all(feature = "tls-rust", not(feature = "tls-native")))] use { - std::sync::Arc, + alloc::sync::Arc, tokio_rustls::{ rustls::pki_types::ServerName, rustls::{ClientConfig, RootCertStore}, diff --git a/tokio-xmpp/src/connect/tcp.rs b/tokio-xmpp/src/connect/tcp.rs index af4722f6e2c58dc51120078ea7aeccfa37cb9e8c..d4c50075fdee32c8a509f99f3e0d5ed30562801a 100644 --- a/tokio-xmpp/src/connect/tcp.rs +++ b/tokio-xmpp/src/connect/tcp.rs @@ -1,6 +1,6 @@ //! `starttls::ServerConfig` provides a `ServerConnector` for starttls connections -use std::borrow::Cow; +use alloc::borrow::Cow; use tokio::{io::BufStream, net::TcpStream}; diff --git a/tokio-xmpp/src/error.rs b/tokio-xmpp/src/error.rs index 79d7b4cbd0d775bbf7426385baeb6dc27005f36a..5fc7c5712e1514e09f2cb1f2609a61e96fb449ba 100644 --- a/tokio-xmpp/src/error.rs +++ b/tokio-xmpp/src/error.rs @@ -1,13 +1,10 @@ +use core::{error::Error as StdError, fmt, net::AddrParseError, str::Utf8Error}; #[cfg(feature = "dns")] use hickory_resolver::{ error::ResolveError as DnsResolveError, proto::error::ProtoError as DnsProtoError, }; use sasl::client::MechanismError as SaslMechanismError; -use std::error::Error as StdError; -use std::fmt; use std::io::Error as IoError; -use std::net::AddrParseError; -use std::str::Utf8Error; use crate::{ connect::ServerConnectorError, jid, minidom, diff --git a/tokio-xmpp/src/lib.rs b/tokio-xmpp/src/lib.rs index 59d903dd8f214f114bede17ceca4c3f28a8a7f8e..b957f2607636d22302309f0774095e8af15b67ed 100644 --- a/tokio-xmpp/src/lib.rs +++ b/tokio-xmpp/src/lib.rs @@ -46,6 +46,8 @@ compile_error!( "when starttls feature enabled one of tls-native and tls-rust features must be enabled." ); +extern crate alloc; + pub use parsers::{jid, minidom}; pub use xmpp_parsers as parsers; diff --git a/tokio-xmpp/src/xmlstream/common.rs b/tokio-xmpp/src/xmlstream/common.rs index ca82c419ec8faa9fa5b2794d1f64f2d396f50188..0fe53b136cc27b5bc133c3318b00ce1760d2172d 100644 --- a/tokio-xmpp/src/xmlstream/common.rs +++ b/tokio-xmpp/src/xmlstream/common.rs @@ -4,11 +4,13 @@ // 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::future::Future; -use core::pin::Pin; -use core::task::{Context, Poll}; -use core::time::Duration; -use std::borrow::Cow; +use alloc::borrow::Cow; +use core::{ + future::Future, + pin::Pin, + task::{Context, Poll}, + time::Duration, +}; use std::io; use futures::{ready, Sink, SinkExt, Stream, StreamExt}; diff --git a/tokio-xmpp/src/xmlstream/mod.rs b/tokio-xmpp/src/xmlstream/mod.rs index 27c51ea32b2474509f940ee5f43fe08abab8a3bd..b24baf0318283c3de2da087279aadaa8cbdba302 100644 --- a/tokio-xmpp/src/xmlstream/mod.rs +++ b/tokio-xmpp/src/xmlstream/mod.rs @@ -114,7 +114,7 @@ struct LogXsoBuf<'x>(&'x [u8]); impl<'x> fmt::Display for LogXsoBuf<'x> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // We always generate UTF-8, so this should be good... I think. - let text = std::str::from_utf8(&self.0).unwrap(); + let text = core::str::from_utf8(&self.0).unwrap(); #[cfg(feature = "syntax-highlighting")] let text = highlight_xml(text); f.write_str(&text) @@ -195,7 +195,7 @@ impl fmt::Display for ReadError { } impl core::error::Error for ReadError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { ReadError::HardError(e) => Some(e), ReadError::ParseError(e) => Some(e), diff --git a/tokio-xmpp/src/xmlstream/tests.rs b/tokio-xmpp/src/xmlstream/tests.rs index b45ddd8620519d25f51544983a244e5c55f8e31f..e81045f8e711b8f52b4c664e091e5ac6c90d9692 100644 --- a/tokio-xmpp/src/xmlstream/tests.rs +++ b/tokio-xmpp/src/xmlstream/tests.rs @@ -4,7 +4,7 @@ // 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 std::time::Duration; +use core::time::Duration; use futures::{SinkExt, StreamExt};