style(lib): run rustfmt and enforce in CI
This commit is contained in:
		| @@ -22,11 +22,11 @@ | ||||
| //! }); | ||||
| //! ``` | ||||
| use std::error::Error; | ||||
| use std::future::Future; | ||||
| use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs}; | ||||
| use std::pin::Pin; | ||||
| use std::str::FromStr; | ||||
| use std::task::{self, Poll}; | ||||
| use std::pin::Pin; | ||||
| use std::future::Future; | ||||
| use std::{fmt, io, vec}; | ||||
|  | ||||
| use tokio::task::JoinHandle; | ||||
| @@ -394,7 +394,8 @@ mod tests { | ||||
|         let dst = ::http::Uri::from_static("http://[::1]:8080/"); | ||||
|  | ||||
|         let mut addrs = | ||||
|             IpAddrs::try_parse(dst.host().expect("host"), dst.port_u16().expect("port")).expect("try_parse"); | ||||
|             IpAddrs::try_parse(dst.host().expect("host"), dst.port_u16().expect("port")) | ||||
|                 .expect("try_parse"); | ||||
|  | ||||
|         let expected = "[::1]:8080".parse::<SocketAddr>().expect("expected"); | ||||
|  | ||||
|   | ||||
| @@ -1,12 +1,12 @@ | ||||
| use std::error::Error as StdError; | ||||
| use std::future::Future; | ||||
| use std::marker::PhantomData; | ||||
| use std::pin::Pin; | ||||
| use std::task::{self, Poll}; | ||||
| use std::fmt; | ||||
| use std::future::Future; | ||||
| use std::io; | ||||
| use std::marker::PhantomData; | ||||
| use std::net::{IpAddr, SocketAddr}; | ||||
| use std::pin::Pin; | ||||
| use std::sync::Arc; | ||||
| use std::task::{self, Poll}; | ||||
| use std::time::Duration; | ||||
|  | ||||
| use futures_util::future::Either; | ||||
| @@ -20,7 +20,6 @@ use super::dns::{self, resolve, GaiResolver, Resolve}; | ||||
| use super::{Connected, Connection}; | ||||
| //#[cfg(feature = "runtime")] use super::dns::TokioThreadpoolGaiResolver; | ||||
|  | ||||
|  | ||||
| /// A connector for the `http` scheme. | ||||
| /// | ||||
| /// Performs DNS resolution in a thread pool, and then connects over TCP. | ||||
| @@ -256,10 +255,7 @@ impl<R> HttpConnector<R> | ||||
| where | ||||
|     R: Resolve, | ||||
| { | ||||
|     async fn call_async( | ||||
|         &mut self, | ||||
|         dst: Uri, | ||||
|     ) -> Result<TcpStream, ConnectError> { | ||||
|     async fn call_async(&mut self, dst: Uri) -> Result<TcpStream, ConnectError> { | ||||
|         trace!( | ||||
|             "Http::connect; scheme={:?}, host={:?}, port={:?}", | ||||
|             dst.scheme(), | ||||
| @@ -292,7 +288,13 @@ where | ||||
|         }; | ||||
|         let port = match dst.port() { | ||||
|             Some(port) => port.as_u16(), | ||||
|             None => if dst.scheme() == Some(&Scheme::HTTPS) { 443 } else { 80 }, | ||||
|             None => { | ||||
|                 if dst.scheme() == Some(&Scheme::HTTPS) { | ||||
|                     443 | ||||
|                 } else { | ||||
|                     80 | ||||
|                 } | ||||
|             } | ||||
|         }; | ||||
|  | ||||
|         let config = &self.config; | ||||
| @@ -348,9 +350,7 @@ impl Connection for TcpStream { | ||||
|     fn connected(&self) -> Connected { | ||||
|         let connected = Connected::new(); | ||||
|         if let Ok(remote_addr) = self.peer_addr() { | ||||
|             connected.extra(HttpInfo { | ||||
|                 remote_addr, | ||||
|             }) | ||||
|             connected.extra(HttpInfo { remote_addr }) | ||||
|         } else { | ||||
|             connected | ||||
|         } | ||||
| @@ -389,7 +389,6 @@ impl<R: Resolve> Future for HttpConnecting<R> { | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| // Not publicly exported (so missing_docs doesn't trigger). | ||||
| pub struct ConnectError { | ||||
|     msg: Box<str>, | ||||
| @@ -531,14 +530,7 @@ impl ConnectingTcpRemote { | ||||
|         let mut err = None; | ||||
|         for addr in &mut self.addrs { | ||||
|             debug!("connecting to {}", addr); | ||||
|             match connect( | ||||
|                 &addr, | ||||
|                 local_addr, | ||||
|                 reuse_address, | ||||
|                 self.connect_timeout, | ||||
|             )? | ||||
|             .await | ||||
|             { | ||||
|             match connect(&addr, local_addr, reuse_address, self.connect_timeout)?.await { | ||||
|                 Ok(tcp) => { | ||||
|                     debug!("connected to {:?}", tcp.peer_addr().ok()); | ||||
|                     return Ok(tcp); | ||||
| @@ -606,13 +598,9 @@ impl ConnectingTcp { | ||||
|             .. | ||||
|         } = self; | ||||
|         match self.fallback { | ||||
|             None => { | ||||
|                 self.preferred | ||||
|                     .connect(local_addr, reuse_address) | ||||
|                     .await | ||||
|             } | ||||
|             None => self.preferred.connect(local_addr, reuse_address).await, | ||||
|             Some(mut fallback) => { | ||||
|                 let preferred_fut = self.preferred.connect(local_addr,  reuse_address); | ||||
|                 let preferred_fut = self.preferred.connect(local_addr, reuse_address); | ||||
|                 futures_util::pin_mut!(preferred_fut); | ||||
|  | ||||
|                 let fallback_fut = fallback.remote.connect(local_addr, reuse_address); | ||||
| @@ -652,10 +640,7 @@ mod tests { | ||||
|     use super::super::sealed::Connect; | ||||
|     use super::HttpConnector; | ||||
|  | ||||
|     async fn connect<C>( | ||||
|         connector: C, | ||||
|         dst: Uri, | ||||
|     ) -> Result<C::Transport, C::Error> | ||||
|     async fn connect<C>(connector: C, dst: Uri) -> Result<C::Transport, C::Error> | ||||
|     where | ||||
|         C: Connect, | ||||
|     { | ||||
| @@ -795,7 +780,6 @@ mod tests { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|  | ||||
|             let (start, stream) = rt | ||||
|                 .block_on(async move { | ||||
|                     let addrs = hosts | ||||
|   | ||||
| @@ -7,11 +7,14 @@ | ||||
| //! - Types to build custom connectors. | ||||
| use std::fmt; | ||||
|  | ||||
| use ::http::{Response}; | ||||
| use ::http::Response; | ||||
|  | ||||
| #[cfg(feature = "tcp")] pub mod dns; | ||||
| #[cfg(feature = "tcp")] mod http; | ||||
| #[cfg(feature = "tcp")] pub use self::http::{HttpConnector, HttpInfo}; | ||||
| #[cfg(feature = "tcp")] | ||||
| pub mod dns; | ||||
| #[cfg(feature = "tcp")] | ||||
| mod http; | ||||
| #[cfg(feature = "tcp")] | ||||
| pub use self::http::{HttpConnector, HttpInfo}; | ||||
|  | ||||
| /// Describes a type returned by a connector. | ||||
| pub trait Connection { | ||||
| @@ -115,8 +118,7 @@ impl Clone for Extra { | ||||
|  | ||||
| impl fmt::Debug for Extra { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||
|         f.debug_struct("Extra") | ||||
|             .finish() | ||||
|         f.debug_struct("Extra").finish() | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -133,7 +135,7 @@ struct ExtraEnvelope<T>(T); | ||||
|  | ||||
| impl<T> ExtraInner for ExtraEnvelope<T> | ||||
| where | ||||
|     T: Clone + Send + Sync + 'static | ||||
|     T: Clone + Send + Sync + 'static, | ||||
| { | ||||
|     fn clone_box(&self) -> Box<dyn ExtraInner> { | ||||
|         Box::new(self.clone()) | ||||
| @@ -154,7 +156,7 @@ impl<T: Clone> Clone for ExtraChain<T> { | ||||
|  | ||||
| impl<T> ExtraInner for ExtraChain<T> | ||||
| where | ||||
|     T: Clone + Send + Sync + 'static | ||||
|     T: Clone + Send + Sync + 'static, | ||||
| { | ||||
|     fn clone_box(&self) -> Box<dyn ExtraInner> { | ||||
|         Box::new(self.clone()) | ||||
| @@ -172,8 +174,8 @@ pub(super) mod sealed { | ||||
|     use ::http::Uri; | ||||
|     use tokio::io::{AsyncRead, AsyncWrite}; | ||||
|  | ||||
|     use super::Connection; | ||||
|     use crate::common::{Future, Unpin}; | ||||
|     use super::{Connection}; | ||||
|  | ||||
|     /// Connect to a destination, returning an IO transport. | ||||
|     /// | ||||
| @@ -193,14 +195,14 @@ pub(super) mod sealed { | ||||
|         /// An error occured when trying to connect. | ||||
|         type Error: Into<Box<dyn StdError + Send + Sync>>; | ||||
|         /// A Future that will resolve to the connected Transport. | ||||
|         type Future: Future<Output=Result<Self::Transport, Self::Error>>; | ||||
|         type Future: Future<Output = Result<Self::Transport, Self::Error>>; | ||||
|         #[doc(hidden)] | ||||
|         fn connect(self, internal_only: Internal, dst: Uri) -> Self::Future; | ||||
|     } | ||||
|  | ||||
|     impl<S, T> Connect for S | ||||
|     where | ||||
|         S: tower_service::Service<Uri, Response=T> + Send, | ||||
|         S: tower_service::Service<Uri, Response = T> + Send, | ||||
|         S::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
|         S::Future: Unpin + Send, | ||||
|         T: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static, | ||||
| @@ -215,11 +217,12 @@ pub(super) mod sealed { | ||||
|  | ||||
|     impl<S, T> Sealed for S | ||||
|     where | ||||
|         S: tower_service::Service<Uri, Response=T> + Send, | ||||
|         S: tower_service::Service<Uri, Response = T> + Send, | ||||
|         S::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
|         S::Future: Unpin + Send, | ||||
|         T: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static, | ||||
|     {} | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     pub trait Sealed {} | ||||
|     #[allow(missing_debug_implementations)] | ||||
| @@ -228,7 +231,7 @@ pub(super) mod sealed { | ||||
|  | ||||
| #[cfg(test)] | ||||
| mod tests { | ||||
|     use super::{Connected}; | ||||
|     use super::Connected; | ||||
|  | ||||
|     #[derive(Clone, Debug, PartialEq)] | ||||
|     struct Ex1(usize); | ||||
| @@ -241,18 +244,13 @@ mod tests { | ||||
|  | ||||
|     #[test] | ||||
|     fn test_connected_extra() { | ||||
|         let c1 = Connected::new() | ||||
|             .extra(Ex1(41)); | ||||
|         let c1 = Connected::new().extra(Ex1(41)); | ||||
|  | ||||
|         let mut res1 = crate::Response::new(crate::Body::empty()); | ||||
|  | ||||
|         assert_eq!(res1.extensions().get::<Ex1>(), None); | ||||
|  | ||||
|         c1 | ||||
|             .extra | ||||
|             .as_ref() | ||||
|             .expect("c1 extra") | ||||
|             .set(&mut res1); | ||||
|         c1.extra.as_ref().expect("c1 extra").set(&mut res1); | ||||
|  | ||||
|         assert_eq!(res1.extensions().get::<Ex1>(), Some(&Ex1(41))); | ||||
|     } | ||||
| @@ -273,11 +271,7 @@ mod tests { | ||||
|         assert_eq!(res1.extensions().get::<Ex2>(), None); | ||||
|         assert_eq!(res1.extensions().get::<Ex3>(), None); | ||||
|  | ||||
|         c1 | ||||
|             .extra | ||||
|             .as_ref() | ||||
|             .expect("c1 extra") | ||||
|             .set(&mut res1); | ||||
|         c1.extra.as_ref().expect("c1 extra").set(&mut res1); | ||||
|  | ||||
|         assert_eq!(res1.extensions().get::<Ex1>(), Some(&Ex1(45))); | ||||
|         assert_eq!(res1.extensions().get::<Ex2>(), Some(&Ex2("zoom"))); | ||||
| @@ -291,11 +285,7 @@ mod tests { | ||||
|  | ||||
|         let mut res2 = crate::Response::new(crate::Body::empty()); | ||||
|  | ||||
|         c2 | ||||
|             .extra | ||||
|             .as_ref() | ||||
|             .expect("c2 extra") | ||||
|             .set(&mut res2); | ||||
|         c2.extra.as_ref().expect("c2 extra").set(&mut res2); | ||||
|  | ||||
|         assert_eq!(res2.extensions().get::<Ex1>(), Some(&Ex1(99))); | ||||
|         assert_eq!(res2.extensions().get::<Ex2>(), Some(&Ex2("hiccup"))); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user