From 49c0f6e7a6cabc4c08571aaf895209fef73663cf Mon Sep 17 00:00:00 2001 From: Astro Date: Mon, 14 Jan 2019 00:02:02 +0100 Subject: [PATCH] client: add new_with_jid() to reuse parsed Jid Should fix Gitlab issue #2 --- src/client/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index 3767013..146d51a 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -45,12 +45,19 @@ impl Client { /// and yield events. pub fn new(jid: &str, password: &str) -> Result { let jid = Jid::from_str(jid)?; + let client = Self::new_with_jid(jid, password); + Ok(client) + } + + /// Start a new client given that the JID is already parsed. + pub fn new_with_jid(jid: Jid, password: &str) -> Self { let password = password.to_owned(); let connect = Self::make_connect(jid.clone(), password.clone()); - Ok(Client { + let client = Client { jid, state: ClientState::Connecting(Box::new(connect)), - }) + }; + client } fn make_connect(jid: Jid, password: String) -> impl Future {