From 1e1f593233fbf450da042c729cbe9721356ad6d7 Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 30 May 2020 00:14:32 +0200 Subject: [PATCH] tokio-xmpp: rustfmt --- tokio-xmpp/examples/send_message.rs | 2 +- tokio-xmpp/src/client/async_client.rs | 10 +++++---- tokio-xmpp/src/client/auth.rs | 5 +---- tokio-xmpp/src/client/mod.rs | 2 +- tokio-xmpp/src/client/simple_client.rs | 27 +++++++++++++---------- tokio-xmpp/src/lib.rs | 8 +++---- tokio-xmpp/src/stream_features.rs | 30 +++++++++++--------------- tokio-xmpp/src/xmpp_codec.rs | 12 +++++++---- tokio-xmpp/src/xmpp_stream.rs | 2 +- 9 files changed, 51 insertions(+), 47 deletions(-) diff --git a/tokio-xmpp/examples/send_message.rs b/tokio-xmpp/examples/send_message.rs index 11349f19..9c54a8bc 100644 --- a/tokio-xmpp/examples/send_message.rs +++ b/tokio-xmpp/examples/send_message.rs @@ -1,5 +1,5 @@ -use std::io::{Read, stdin}; use std::env::args; +use std::io::{stdin, Read}; use std::process::exit; use std::str::FromStr; use tokio; diff --git a/tokio-xmpp/src/client/async_client.rs b/tokio-xmpp/src/client/async_client.rs index 4df34077..d9d55ee5 100644 --- a/tokio-xmpp/src/client/async_client.rs +++ b/tokio-xmpp/src/client/async_client.rs @@ -20,7 +20,6 @@ use crate::xmpp_codec::Packet; use crate::xmpp_stream; use crate::{Error, ProtocolError}; - /// XMPP client connection and state /// /// It is able to reconnect. TODO: implement session management. @@ -86,13 +85,15 @@ impl Client { // Unencryped XMPPStream let xmpp_stream = - xmpp_stream::XMPPStream::start(tcp_stream, jid.clone(), NS_JABBER_CLIENT.to_owned()).await?; + xmpp_stream::XMPPStream::start(tcp_stream, jid.clone(), NS_JABBER_CLIENT.to_owned()) + .await?; let xmpp_stream = if xmpp_stream.stream_features.can_starttls() { // TlsStream let tls_stream = starttls(xmpp_stream).await?; // Encrypted XMPPStream - xmpp_stream::XMPPStream::start(tls_stream, jid.clone(), NS_JABBER_CLIENT.to_owned()).await? + xmpp_stream::XMPPStream::start(tls_stream, jid.clone(), NS_JABBER_CLIENT.to_owned()) + .await? } else { return Err(Error::Protocol(ProtocolError::NoTls)); }; @@ -104,7 +105,8 @@ impl Client { // Authenticated (unspecified) stream let stream = auth(xmpp_stream, creds).await?; // Authenticated XMPPStream - let xmpp_stream = xmpp_stream::XMPPStream::start(stream, jid, NS_JABBER_CLIENT.to_owned()).await?; + let xmpp_stream = + xmpp_stream::XMPPStream::start(stream, jid, NS_JABBER_CLIENT.to_owned()).await?; // XMPPStream bound to user session let xmpp_stream = bind(xmpp_stream).await?; diff --git a/tokio-xmpp/src/client/auth.rs b/tokio-xmpp/src/client/auth.rs index d317bba4..cbabe257 100644 --- a/tokio-xmpp/src/client/auth.rs +++ b/tokio-xmpp/src/client/auth.rs @@ -24,10 +24,7 @@ pub async fn auth( Box::new(|| Box::new(Anonymous::new())), ]; - let remote_mechs: HashSet = stream - .stream_features - .sasl_mechanisms()? - .collect(); + let remote_mechs: HashSet = stream.stream_features.sasl_mechanisms()?.collect(); for local_mech in local_mechs { let mut mechanism = local_mech(); diff --git a/tokio-xmpp/src/client/mod.rs b/tokio-xmpp/src/client/mod.rs index c1000649..c98b01bd 100644 --- a/tokio-xmpp/src/client/mod.rs +++ b/tokio-xmpp/src/client/mod.rs @@ -1,8 +1,8 @@ mod auth; mod bind; -pub mod simple_client; pub mod async_client; +pub mod simple_client; pub const NS_XMPP_SASL: &str = "urn:ietf:params:xml:ns:xmpp-sasl"; pub const NS_XMPP_BIND: &str = "urn:ietf:params:xml:ns:xmpp-bind"; diff --git a/tokio-xmpp/src/client/simple_client.rs b/tokio-xmpp/src/client/simple_client.rs index d12ed9ee..65eceb88 100644 --- a/tokio-xmpp/src/client/simple_client.rs +++ b/tokio-xmpp/src/client/simple_client.rs @@ -8,13 +8,13 @@ use tokio::{net::TcpStream, stream::StreamExt}; use tokio_tls::TlsStream; use xmpp_parsers::{Element, Jid}; +use super::auth::auth; +use super::bind::bind; use crate::happy_eyeballs::connect; use crate::starttls::starttls; use crate::xmpp_codec::Packet; use crate::xmpp_stream; use crate::{Error, ProtocolError}; -use super::auth::auth; -use super::bind::bind; /// A simple XMPP client connection /// @@ -51,13 +51,15 @@ impl Client { // Unencryped XMPPStream let xmpp_stream = - xmpp_stream::XMPPStream::start(tcp_stream, jid.clone(), NS_JABBER_CLIENT.to_owned()).await?; + xmpp_stream::XMPPStream::start(tcp_stream, jid.clone(), NS_JABBER_CLIENT.to_owned()) + .await?; let xmpp_stream = if xmpp_stream.stream_features.can_starttls() { // TlsStream let tls_stream = starttls(xmpp_stream).await?; // Encrypted XMPPStream - xmpp_stream::XMPPStream::start(tls_stream, jid.clone(), NS_JABBER_CLIENT.to_owned()).await? + xmpp_stream::XMPPStream::start(tls_stream, jid.clone(), NS_JABBER_CLIENT.to_owned()) + .await? } else { return Err(Error::Protocol(ProtocolError::NoTls)); }; @@ -69,7 +71,8 @@ impl Client { // Authenticated (unspecified) stream let stream = auth(xmpp_stream, creds).await?; // Authenticated XMPPStream - let xmpp_stream = xmpp_stream::XMPPStream::start(stream, jid, NS_JABBER_CLIENT.to_owned()).await?; + let xmpp_stream = + xmpp_stream::XMPPStream::start(stream, jid, NS_JABBER_CLIENT.to_owned()).await?; // XMPPStream bound to user session let xmpp_stream = bind(xmpp_stream).await?; @@ -115,16 +118,18 @@ impl Stream for Client { fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { loop { match Pin::new(&mut self.stream).poll_next(cx) { - Poll::Pending => - return Poll::Pending, - Poll::Ready(Some(Ok(Packet::Stanza(stanza)))) => - return Poll::Ready(Some(Ok(stanza))), + Poll::Pending => return Poll::Pending, + Poll::Ready(Some(Ok(Packet::Stanza(stanza)))) => { + return Poll::Ready(Some(Ok(stanza))) + } Poll::Ready(Some(Ok(Packet::Text(_)))) => { // Ignore, retry } Poll::Ready(_) => - // Unexpected and errors, just end - return Poll::Ready(None), + // Unexpected and errors, just end + { + return Poll::Ready(None) + } } } } diff --git a/tokio-xmpp/src/lib.rs b/tokio-xmpp/src/lib.rs index 11fc5fa3..9fe857b6 100644 --- a/tokio-xmpp/src/lib.rs +++ b/tokio-xmpp/src/lib.rs @@ -7,11 +7,11 @@ mod stream_start; mod xmpp_codec; pub use crate::xmpp_codec::Packet; mod event; -mod happy_eyeballs; -pub mod xmpp_stream; -pub mod stream_features; -pub use crate::event::Event; +pub use event::Event; mod client; +mod happy_eyeballs; +pub mod stream_features; +pub mod xmpp_stream; pub use client::{async_client::Client as AsyncClient, simple_client::Client as SimpleClient}; mod component; pub use crate::component::Component; diff --git a/tokio-xmpp/src/stream_features.rs b/tokio-xmpp/src/stream_features.rs index 32bbd16f..37de82ae 100644 --- a/tokio-xmpp/src/stream_features.rs +++ b/tokio-xmpp/src/stream_features.rs @@ -1,9 +1,9 @@ //! Contains wrapper for `` -use xmpp_parsers::Element; -use crate::starttls::NS_XMPP_TLS; -use crate::client::{NS_XMPP_SASL, NS_XMPP_BIND}; +use crate::client::{NS_XMPP_BIND, NS_XMPP_SASL}; use crate::error::AuthError; +use crate::starttls::NS_XMPP_TLS; +use xmpp_parsers::Element; /// Wraps ``, usually the very first nonza of an /// XMPPStream. @@ -20,26 +20,22 @@ impl StreamFeatures { /// Can initiate TLS session with this server? pub fn can_starttls(&self) -> bool { - self.0 - .get_child("starttls", NS_XMPP_TLS) - .is_some() + self.0.get_child("starttls", NS_XMPP_TLS).is_some() } /// Iterate over SASL mechanisms - pub fn sasl_mechanisms<'a>(&'a self) -> Result + 'a, AuthError> { - Ok(self.0 - .get_child("mechanisms", NS_XMPP_SASL) - .ok_or(AuthError::NoMechanism)? - .children() - .filter(|child| child.is("mechanism", NS_XMPP_SASL)) - .map(|mech_el| mech_el.text()) - ) + pub fn sasl_mechanisms<'a>(&'a self) -> Result + 'a, AuthError> { + Ok(self + .0 + .get_child("mechanisms", NS_XMPP_SASL) + .ok_or(AuthError::NoMechanism)? + .children() + .filter(|child| child.is("mechanism", NS_XMPP_SASL)) + .map(|mech_el| mech_el.text())) } /// Does server support user resource binding? pub fn can_bind(&self) -> bool { - self.0 - .get_child("bind", NS_XMPP_BIND) - .is_some() + self.0.get_child("bind", NS_XMPP_BIND).is_some() } } diff --git a/tokio-xmpp/src/xmpp_codec.rs b/tokio-xmpp/src/xmpp_codec.rs index 9a8a4098..bbc0ee10 100644 --- a/tokio-xmpp/src/xmpp_codec.rs +++ b/tokio-xmpp/src/xmpp_codec.rs @@ -250,7 +250,13 @@ impl Decoder for XMPPCodec { return result; } Err(e) => { - error!("error {} at {}/{} in {:?}", e, e.valid_up_to(), buf1.len(), buf1); + error!( + "error {} at {}/{} in {:?}", + e, + e.valid_up_to(), + buf1.len(), + buf1 + ); return Err(ParserError::Utf8(e)); } } @@ -309,9 +315,7 @@ impl Encoder for XMPPCodec { Ok(()) }) .map_err(to_io_err), - Packet::StreamEnd => - write!(dst, "\n") - .map_err(to_io_err), + Packet::StreamEnd => write!(dst, "\n").map_err(to_io_err), } } } diff --git a/tokio-xmpp/src/xmpp_stream.rs b/tokio-xmpp/src/xmpp_stream.rs index 4cc59ede..173f5de6 100644 --- a/tokio-xmpp/src/xmpp_stream.rs +++ b/tokio-xmpp/src/xmpp_stream.rs @@ -10,8 +10,8 @@ use tokio::io::{AsyncRead, AsyncWrite}; use tokio_util::codec::Framed; use xmpp_parsers::{Element, Jid}; -use crate::stream_start; use crate::stream_features::StreamFeatures; +use crate::stream_start; use crate::xmpp_codec::{Packet, XMPPCodec}; use crate::Error;