diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-10-22 06:46:29 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-10-22 06:46:29 -0400 |
commit | 036f51ad6deddaf149685e6fd4945b1ed30543e3 (patch) | |
tree | bb2d24faf3eeb1b00ef295739d103768d9e8aa80 /src/cmd/stream.rs | |
parent | d6472faae56121d53f87c8ccffe40cf0a3d815dc (diff) | |
download | teleterm-036f51ad6deddaf149685e6fd4945b1ed30543e3.tar.gz teleterm-036f51ad6deddaf149685e6fd4945b1ed30543e3.zip |
remove some duplication
Diffstat (limited to 'src/cmd/stream.rs')
-rw-r--r-- | src/cmd/stream.rs | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/cmd/stream.rs b/src/cmd/stream.rs index ed9b980..0b60925 100644 --- a/src/cmd/stream.rs +++ b/src/cmd/stream.rs @@ -20,17 +20,20 @@ impl crate::config::Config for Config { Ok(()) } - fn run(&self) -> Result<()> { - let host = self.client.host().to_string(); - let address = *self.client.addr(); + fn run( + &self, + ) -> Box<dyn futures::future::Future<Item = (), Error = Error> + Send> { let auth = match self.client.auth { crate::protocol::AuthType::Plain => { let username = self .client .username .clone() - .context(crate::error::CouldntFindUsername)?; - crate::protocol::Auth::plain(&username) + .context(crate::error::CouldntFindUsername); + match username { + Ok(username) => crate::protocol::Auth::plain(&username), + Err(e) => return Box::new(futures::future::err(e)), + } } crate::protocol::AuthType::RecurseCenter => { let id = crate::oauth::load_client_auth_id(self.client.auth); @@ -39,11 +42,16 @@ impl crate::config::Config for Config { ) } }; - let fut: Box< - dyn futures::future::Future<Item = (), Error = Error> + Send, - > = if self.client.tls { - let connector = native_tls::TlsConnector::new() - .context(crate::error::CreateConnector)?; + + let host = self.client.host().to_string(); + let address = *self.client.addr(); + if self.client.tls { + let connector = match native_tls::TlsConnector::new() + .context(crate::error::CreateConnector) + { + Ok(connector) => connector, + Err(e) => return Box::new(futures::future::err(e)), + }; let connect: crate::client::Connector<_> = Box::new(move || { let host = host.clone(); let connector = connector.clone(); @@ -80,11 +88,7 @@ impl crate::config::Config for Config { self.command.buffer_size, &auth, )) - }; - tokio::run(fut.map_err(|e| { - log::error!("{}", e); - })); - Ok(()) + } } } |