Move SimpleClient constructors to client::simple_client module

This commit is contained in:
xmppftw 2024-08-03 15:23:00 +02:00
parent fc0071a0c5
commit b3fd0b5372
3 changed files with 15 additions and 21 deletions

View file

@ -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<C: ServerConnector> {
stream: XMPPStream<C::Stream>,
}
impl Client<ServerConfig> {
/// Start a new XMPP client and wait for a usable session
pub async fn new<P: Into<String>>(jid: &str, password: P) -> Result<Self, Error> {
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, Error> {
Self::new_with_jid_connector(ServerConfig::UseSrv, jid, password).await
}
}
impl<C: ServerConnector> Client<C> {
/// Start a new client given that the JID is already parsed.
pub async fn new_with_jid_connector(

View file

@ -1,20 +0,0 @@
use std::str::FromStr;
use xmpp_parsers::jid::Jid;
use crate::{Error, SimpleClient};
use super::ServerConfig;
impl SimpleClient<ServerConfig> {
/// Start a new XMPP client and wait for a usable session
pub async fn new<P: Into<String>>(jid: &str, password: P) -> Result<Self, Error> {
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, Error> {
Self::new_with_jid_connector(ServerConfig::UseSrv, jid, password).await
}
}

View file

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