From 4c60e6d35fe592e67119c257d3f9a13057e658d5 Mon Sep 17 00:00:00 2001 From: Tom Prince Date: Wed, 31 May 2017 14:42:50 -0600 Subject: [PATCH] Really trivial rustfmt changes. --- examples/response_json.rs | 6 ++++-- examples/simple.rs | 3 ++- src/client.rs | 35 +++++++++++++++++++---------------- src/error.rs | 14 +++++++++----- src/lib.rs | 3 ++- src/redirect.rs | 10 ++++++---- src/response.rs | 19 +++++++++---------- tests/client.rs | 7 ++++--- tests/server.rs | 2 +- 9 files changed, 56 insertions(+), 43 deletions(-) diff --git a/examples/response_json.rs b/examples/response_json.rs index faa463e..b3dbc08 100644 --- a/examples/response_json.rs +++ b/examples/response_json.rs @@ -1,7 +1,9 @@ //! `cargo run --example response_json` extern crate reqwest; -#[macro_use] extern crate serde_derive; -#[macro_use] extern crate error_chain; +#[macro_use] +extern crate serde_derive; +#[macro_use] +extern crate error_chain; error_chain! { foreign_links { diff --git a/examples/simple.rs b/examples/simple.rs index d8c8284..c188d31 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,7 +1,8 @@ //! `cargo run --example simple` extern crate reqwest; extern crate env_logger; -#[macro_use] extern crate error_chain; +#[macro_use] +extern crate error_chain; error_chain! { foreign_links { diff --git a/src/client.rs b/src/client.rs index 112d945..7d632c7 100644 --- a/src/client.rs +++ b/src/client.rs @@ -5,11 +5,11 @@ use std::time::Duration; use hyper::client::IntoUrl; use hyper::header::{Headers, ContentType, Location, Referer, UserAgent, Accept, Encoding, - AcceptEncoding, Range, qitem}; + AcceptEncoding, Range, qitem}; use hyper::method::Method; use hyper::status::StatusCode; use hyper::version::HttpVersion; -use hyper::{Url}; +use hyper::Url; use hyper_native_tls::{NativeTlsClient, native_tls}; @@ -17,9 +17,9 @@ use serde::Serialize; use serde_json; use serde_urlencoded; -use ::body::{self, Body}; -use ::redirect::{self, RedirectPolicy, check_redirect, remove_sensitive_headers}; -use ::response::Response; +use body::{self, Body}; +use redirect::{self, RedirectPolicy, check_redirect, remove_sensitive_headers}; +use response::Response; static DEFAULT_USER_AGENT: &'static str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); @@ -328,7 +328,8 @@ impl RequestBuilder { /// # } /// ``` pub fn header(mut self, header: H) -> RequestBuilder - where H: ::header::Header + ::header::HeaderFormat + where + H: ::header::Header + ::header::HeaderFormat, { self.headers.set(header); self @@ -343,7 +344,9 @@ impl RequestBuilder { /// Enable HTTP basic authentication. pub fn basic_auth(self, username: U, password: Option

) -> RequestBuilder - where U: Into, P: Into + where + U: Into, + P: Into, { self.header(::header::Authorization(::header::Basic{ username: username.into(), @@ -458,13 +461,13 @@ impl RequestBuilder { StatusCode::SeeOther => { body = None; match method { - Method::Get | Method::Head => {}, + Method::Get | Method::Head => {} _ => { method = Method::Get; } } true - }, + } StatusCode::TemporaryRedirect | StatusCode::PermanentRedirect => { if let Some(ref body) = body { @@ -472,7 +475,7 @@ impl RequestBuilder { } else { true } - }, + } _ => false, }; @@ -501,26 +504,26 @@ impl RequestBuilder { redirect::Action::Stop => { debug!("redirect_policy disallowed redirection to '{}'", loc); return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed))); - }, + } redirect::Action::LoopDetected => { return Err(::error::loop_detected(res.url.clone())); - }, + } redirect::Action::TooManyRedirects => { return Err(::error::too_many_redirects(res.url.clone())); } } - }, + } Err(e) => { debug!("Location header had invalid URI: {:?}", e); - return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed))) + return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed))); } }; remove_sensitive_headers(&mut headers, &url, &urls); debug!("redirecting to {:?} '{}'", method, url); } else { - return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed))) + return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed))); } } } @@ -551,7 +554,7 @@ fn make_referer(next: &Url, previous: &Url) -> Option { #[cfg(test)] mod tests { use super::*; - use ::body; + use body; use hyper::method::Method; use hyper::Url; use hyper::header::{Host, Headers, ContentType}; diff --git a/src/error.rs b/src/error.rs index 9eba058..d696597 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,7 @@ use std::error::Error as StdError; use std::fmt; -use ::Url; +use Url; /// The Errors that may occur when processing a `Request`. #[derive(Debug)] @@ -153,10 +153,12 @@ impl From> for Error { } impl From> for Error -where T: Into { +where + T: Into, +{ #[inline] fn from(other: InternalFrom) -> Error { - Error { + Error { kind: other.0.into(), url: other.1, } @@ -165,7 +167,9 @@ where T: Into { #[inline] pub fn from(err: T) -> Error -where T: Into { +where + T: Into, +{ InternalFrom(err, None).into() } @@ -193,6 +197,6 @@ fn test_error_get_ref_downcasts() { match cause { &::hyper::Error::Status => (), - _ => panic!("unexpected downcast: {:?}", cause) + _ => panic!("unexpected downcast: {:?}", cause), } } diff --git a/src/lib.rs b/src/lib.rs index 3b25fd1..e9080af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -115,7 +115,8 @@ //! [serde]: http://serde.rs extern crate hyper; -#[macro_use] extern crate log; +#[macro_use] +extern crate log; extern crate libflate; extern crate hyper_native_tls; extern crate serde; diff --git a/src/redirect.rs b/src/redirect.rs index 695cf3c..53a87da 100644 --- a/src/redirect.rs +++ b/src/redirect.rs @@ -2,7 +2,7 @@ use std::fmt; use hyper::header::{Headers, Authorization, Cookie}; -use ::Url; +use Url; /// A type that controls the policy on how to handle the following of redirects. /// @@ -77,7 +77,9 @@ impl RedirectPolicy { /// # } /// ``` pub fn custom(policy: T) -> RedirectPolicy - where T: Fn(RedirectAttempt) -> RedirectAction + Send + Sync + 'static { + where + T: Fn(RedirectAttempt) -> RedirectAction + Send + Sync + 'static, + { RedirectPolicy { inner: Policy::Custom(Box::new(policy)), } @@ -94,7 +96,7 @@ impl RedirectPolicy { } else { attempt.follow() } - }, + } Policy::None => attempt.stop(), } } @@ -262,7 +264,7 @@ fn test_remove_sensitive_headers() { ]) ); - let next = Url::parse("http://initial-domain.com/path").unwrap(); + let next = Url::parse("http://initial-domain.com/path").unwrap(); let mut prev = vec![Url::parse("http://initial-domain.com/new_path").unwrap()]; let mut filtered_headers = headers.clone(); diff --git a/src/response.rs b/src/response.rs index 21906de..31d07d7 100644 --- a/src/response.rs +++ b/src/response.rs @@ -18,7 +18,7 @@ pub struct Response { pub fn new(res: ::hyper::client::Response, gzip: bool) -> Response { info!("Response: '{}' for {}", res.status, res.url); Response { - inner: Decoder::from_hyper_response(res, gzip) + inner: Decoder::from_hyper_response(res, gzip), } } @@ -32,8 +32,8 @@ impl fmt::Debug for Response { .field("headers", &hyper_response.headers) .field("version", &hyper_response.version) .finish() - }, - Decoder::Gzip{ ref head, .. } | + } + Decoder::Gzip { ref head, .. } | Decoder::Errored { ref head, .. } => { f.debug_struct("Response") .field("url", &head.url) @@ -52,7 +52,7 @@ impl Response { pub fn url(&self) -> &Url { match self.inner { Decoder::PlainText(ref hyper_response) => &hyper_response.url, - Decoder::Gzip{ ref head, .. } | + Decoder::Gzip { ref head, .. } | Decoder::Errored { ref head, .. } => &head.url, } } @@ -62,7 +62,7 @@ impl Response { pub fn status(&self) -> &StatusCode { match self.inner { Decoder::PlainText(ref hyper_response) => &hyper_response.status, - Decoder::Gzip{ ref head, .. } | + Decoder::Gzip { ref head, .. } | Decoder::Errored { ref head, .. } => &head.status, } } @@ -72,7 +72,7 @@ impl Response { pub fn headers(&self) -> &Headers { match self.inner { Decoder::PlainText(ref hyper_response) => &hyper_response.headers, - Decoder::Gzip{ ref head, .. } | + Decoder::Gzip { ref head, .. } | Decoder::Errored { ref head, .. } => &head.headers, } } @@ -82,7 +82,7 @@ impl Response { pub fn version(&self) -> &HttpVersion { match self.inner { Decoder::PlainText(ref hyper_response) => &hyper_response.version, - Decoder::Gzip{ ref head, .. } | + Decoder::Gzip { ref head, .. } | Decoder::Errored { ref head, .. } => &head.version, } } @@ -184,7 +184,7 @@ fn new_gzip(mut res: ::hyper::client::Response) -> Decoder { Ok(0) => return Decoder::PlainText(res), Ok(n) => { debug_assert_eq!(n, 1); - }, + } Err(e) => return Decoder::Errored { err: Some(e), head: Head { @@ -193,7 +193,7 @@ fn new_gzip(mut res: ::hyper::client::Response) -> Decoder { url: res.url.clone(), version: res.version, } - }, + } } let head = Head { @@ -274,4 +274,3 @@ impl Read for Response { self.inner.read(buf) } } - diff --git a/tests/client.rs b/tests/client.rs index e260840..9a23c6f 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -1,7 +1,8 @@ extern crate reqwest; extern crate libflate; -#[macro_use] mod server; +#[macro_use] +mod server; use std::io::Read; use std::io::prelude::*; @@ -395,7 +396,7 @@ fn test_gzip_response() { let mut encoder = ::libflate::gzip::Encoder::new(Vec::new()).unwrap(); match encoder.write(b"test request") { Ok(n) => assert!(n > 0, "Failed to write to encoder."), - _ => panic!("Failed to gzip encode string.") + _ => panic!("Failed to gzip encode string."), }; let gzipped_content = encoder.finish().into_result().unwrap(); @@ -426,7 +427,7 @@ fn test_gzip_response() { let mut body = ::std::string::String::new(); match res.read_to_string(&mut body) { Ok(n) => assert!(n > 0, "Failed to write to buffer."), - _ => panic!("Failed to write to buffer.") + _ => panic!("Failed to write to buffer."), }; assert_eq!(body, "test request"); diff --git a/tests/server.rs b/tests/server.rs index 749b8fd..a97d7dd 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -28,7 +28,7 @@ pub fn spawn(txns: Vec<(Vec, Vec)>) -> Server { match (::std::str::from_utf8(&expected), ::std::str::from_utf8(&buf[..n])) { (Ok(expected), Ok(received)) => assert_eq!(expected, received), - _ => assert_eq!(expected, &buf[..n]) + _ => assert_eq!(expected, &buf[..n]), } socket.write_all(&reply).unwrap(); }