tokio-xmpp: rustfmt

Astro created

Change summary

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                  |  6 ++--
tokio-xmpp/src/stream_features.rs      | 30 ++++++++++++---------------
tokio-xmpp/src/xmpp_codec.rs           | 12 +++++++---
tokio-xmpp/src/xmpp_stream.rs          |  2 
9 files changed, 50 insertions(+), 46 deletions(-)

Detailed changes

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

tokio-xmpp/src/client/auth.rs 🔗

@@ -24,10 +24,7 @@ pub async fn auth<S: AsyncRead + AsyncWrite + Unpin>(
         Box::new(|| Box::new(Anonymous::new())),
     ];
 
-    let remote_mechs: HashSet<String> = stream
-        .stream_features
-        .sasl_mechanisms()?
-        .collect();
+    let remote_mechs: HashSet<String> = stream.stream_features.sasl_mechanisms()?.collect();
 
     for local_mech in local_mechs {
         let mut mechanism = local_mech();

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

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<Option<Self::Item>> {
         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)
+                }
             }
         }
     }

tokio-xmpp/src/lib.rs 🔗

@@ -7,11 +7,11 @@ mod stream_start;
 mod xmpp_codec;
 pub use crate::xmpp_codec::Packet;
 mod event;
+pub use event::Event;
+mod client;
 mod happy_eyeballs;
-pub mod xmpp_stream;
 pub mod stream_features;
-pub use crate::event::Event;
-mod client;
+pub mod xmpp_stream;
 pub use client::{async_client::Client as AsyncClient, simple_client::Client as SimpleClient};
 mod component;
 pub use crate::component::Component;

tokio-xmpp/src/stream_features.rs 🔗

@@ -1,9 +1,9 @@
 //! Contains wrapper for `<stream:features/>`
 
-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 `<stream:features/>`, 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<impl Iterator<Item=String> + '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<impl Iterator<Item = String> + '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()
     }
 }

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, "</stream:stream>\n")
-                    .map_err(to_io_err),
+            Packet::StreamEnd => write!(dst, "</stream:stream>\n").map_err(to_io_err),
         }
     }
 }

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;