From b3fd0b537265d84eac9be8879848538d6e339258 Mon Sep 17 00:00:00 2001 From: xmppftw Date: Sat, 3 Aug 2024 15:23:00 +0200 Subject: [PATCH] Move SimpleClient constructors to client::simple_client module --- tokio-xmpp/src/client/simple_client.rs | 15 +++++++++++++++ tokio-xmpp/src/starttls/client.rs | 20 -------------------- tokio-xmpp/src/starttls/mod.rs | 1 - 3 files changed, 15 insertions(+), 21 deletions(-) delete mode 100644 tokio-xmpp/src/starttls/client.rs diff --git a/tokio-xmpp/src/client/simple_client.rs b/tokio-xmpp/src/client/simple_client.rs index d5020d1e..d57e82e0 100644 --- a/tokio-xmpp/src/client/simple_client.rs +++ b/tokio-xmpp/src/client/simple_client.rs @@ -1,11 +1,13 @@ use futures::{sink::SinkExt, Sink, Stream}; use minidom::Element; use std::pin::Pin; +use std::str::FromStr; use std::task::{Context, Poll}; use tokio_stream::StreamExt; use xmpp_parsers::{jid::Jid, ns, stream_features::StreamFeatures}; use crate::connect::ServerConnector; +use crate::starttls::ServerConfig; use crate::xmpp_codec::Packet; use crate::xmpp_stream::{add_stanza_id, XMPPStream}; use crate::Error; @@ -20,6 +22,19 @@ pub struct Client { stream: XMPPStream, } +impl Client { + /// Start a new XMPP client and wait for a usable session + pub async fn new>(jid: &str, password: P) -> Result { + let jid = Jid::from_str(jid)?; + Self::new_with_jid(jid, password.into()).await + } + + /// Start a new client given that the JID is already parsed. + pub async fn new_with_jid(jid: Jid, password: String) -> Result { + Self::new_with_jid_connector(ServerConfig::UseSrv, jid, password).await + } +} + impl Client { /// Start a new client given that the JID is already parsed. pub async fn new_with_jid_connector( diff --git a/tokio-xmpp/src/starttls/client.rs b/tokio-xmpp/src/starttls/client.rs deleted file mode 100644 index 8063f37c..00000000 --- a/tokio-xmpp/src/starttls/client.rs +++ /dev/null @@ -1,20 +0,0 @@ -use std::str::FromStr; - -use xmpp_parsers::jid::Jid; - -use crate::{Error, SimpleClient}; - -use super::ServerConfig; - -impl SimpleClient { - /// Start a new XMPP client and wait for a usable session - pub async fn new>(jid: &str, password: P) -> Result { - let jid = Jid::from_str(jid)?; - Self::new_with_jid(jid, password.into()).await - } - - /// Start a new client given that the JID is already parsed. - pub async fn new_with_jid(jid: Jid, password: String) -> Result { - Self::new_with_jid_connector(ServerConfig::UseSrv, jid, password).await - } -} diff --git a/tokio-xmpp/src/starttls/mod.rs b/tokio-xmpp/src/starttls/mod.rs index 673fc96f..0e1e9cb4 100644 --- a/tokio-xmpp/src/starttls/mod.rs +++ b/tokio-xmpp/src/starttls/mod.rs @@ -35,7 +35,6 @@ use crate::{connect::ServerConnectorError, xmpp_stream::XMPPStream}; use self::error::Error as StartTlsError; use self::happy_eyeballs::{connect_to_host, connect_with_srv}; -mod client; pub mod error; mod happy_eyeballs;