Move AsyncClient::new to client::async_client module

This commit is contained in:
xmppftw 2024-08-03 15:17:27 +02:00
parent 84511b54a0
commit fc0071a0c5
2 changed files with 19 additions and 16 deletions

View file

@ -10,8 +10,10 @@ use super::connect::client_login;
use crate::connect::{AsyncReadAndWrite, ServerConnector};
use crate::error::{Error, ProtocolError};
use crate::event::Event;
use crate::starttls::ServerConfig;
use crate::xmpp_codec::Packet;
use crate::xmpp_stream::{add_stanza_id, XMPPStream};
use crate::AsyncConfig;
/// XMPP client connection and state
///
@ -44,6 +46,22 @@ enum ClientState<S: AsyncReadAndWrite> {
Connected(XMPPStream<S>),
}
impl Client<ServerConfig> {
/// Start a new XMPP client using StartTLS transport
///
/// Start polling the returned instance so that it will connect
/// and yield events.
#[cfg(feature = "starttls")]
pub fn new<J: Into<Jid>, P: Into<String>>(jid: J, password: P) -> Self {
let config = AsyncConfig {
jid: jid.into(),
password: password.into(),
server: ServerConfig::UseSrv,
};
Self::new_with_config(config)
}
}
impl<C: ServerConnector> Client<C> {
/// Start a new client given that the JID is already parsed.
pub fn new_with_config(config: Config<C>) -> Self {

View file

@ -2,25 +2,10 @@ use std::str::FromStr;
use xmpp_parsers::jid::Jid;
use crate::{AsyncClient, AsyncConfig, Error, SimpleClient};
use crate::{Error, SimpleClient};
use super::ServerConfig;
impl AsyncClient<ServerConfig> {
/// Start a new XMPP client
///
/// Start polling the returned instance so that it will connect
/// and yield events.
pub fn new<J: Into<Jid>, P: Into<String>>(jid: J, password: P) -> Self {
let config = AsyncConfig {
jid: jid.into(),
password: password.into(),
server: ServerConfig::UseSrv,
};
Self::new_with_config(config)
}
}
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> {