From 85b275bb2b896624ed52d86cf7b93655704fc57e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 24 Jul 2018 14:52:56 -0700 Subject: [PATCH] fix warnings --- Cargo.toml | 2 +- src/client/connector.rs | 8 ++--- src/client/pipeline.rs | 2 +- src/extractor.rs | 65 ++++++++++++++++++++++++++++------------- 4 files changed, 51 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6fb2e1a2e..89a51c66b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ base64 = "0.9" bitflags = "1.0" h2 = "0.1" htmlescape = "0.3" -http = "^0.1.5" +http = "^0.1.8" httparse = "1.3" log = "0.4" mime = "0.3" diff --git a/src/client/connector.rs b/src/client/connector.rs index 6d391af87..03ad3bd98 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -599,7 +599,7 @@ impl ClientConnector { } Acquire::Available => { // create new connection - self.connect_waiter(key.clone(), waiter, ctx); + self.connect_waiter(&key, waiter, ctx); } } } @@ -608,7 +608,7 @@ impl ClientConnector { self.waiters = Some(act_waiters); } - fn connect_waiter(&mut self, key: Key, waiter: Waiter, ctx: &mut Context) { + fn connect_waiter(&mut self, key: &Key, waiter: Waiter, ctx: &mut Context) { let conn = AcquiredConn(key.clone(), Some(self.acq_tx.clone())); let key2 = key.clone(); @@ -828,7 +828,7 @@ impl Handler for ClientConnector { wait, conn_timeout, }; - self.connect_waiter(key.clone(), waiter, ctx); + self.connect_waiter(&key, waiter, ctx); return ActorResponse::async( rx.map_err(|_| ClientConnectorError::Disconnected) @@ -885,7 +885,7 @@ impl Handler for ClientConnector { wait, conn_timeout, }; - self.connect_waiter(key.clone(), waiter, ctx); + self.connect_waiter(&key, waiter, ctx); ActorResponse::async( rx.map_err(|_| ClientConnectorError::Disconnected) diff --git a/src/client/pipeline.rs b/src/client/pipeline.rs index e5538b060..394b7a6cd 100644 --- a/src/client/pipeline.rs +++ b/src/client/pipeline.rs @@ -216,7 +216,7 @@ impl Future for SendRequest { match pl.parse() { Ok(Async::Ready(mut resp)) => { - if self.req.method() == &Method::HEAD { + if self.req.method() == Method::HEAD { pl.parser.take(); } resp.set_pipeline(pl); diff --git a/src/extractor.rs b/src/extractor.rs index 768edfb76..aa4fdea7a 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -6,7 +6,7 @@ use std::{fmt, str}; use bytes::Bytes; use encoding::all::UTF_8; use encoding::types::{DecoderTrap, Encoding}; -use futures::{Async, Future, Poll, future}; +use futures::{future, Async, Future, Poll}; use mime::Mime; use serde::de::{self, DeserializeOwned}; use serde_urlencoded; @@ -504,19 +504,18 @@ impl FromRequest for String { /// }); /// } /// ``` -impl FromRequest for Option where T: FromRequest { +impl FromRequest for Option +where + T: FromRequest, +{ type Config = T::Config; type Result = Box, Error = Error>>; #[inline] fn from_request(req: &HttpRequest, cfg: &Self::Config) -> Self::Result { - Box::new(T::from_request(req, cfg).into().then( |r| { - match r { - Ok(v) => future::ok(Some(v)), - Err(e) => { - future::ok(None) - } - } + Box::new(T::from_request(req, cfg).into().then(|r| match r { + Ok(v) => future::ok(Some(v)), + Err(_) => future::ok(None), })) } } @@ -566,13 +565,16 @@ impl FromRequest for Option where T: FromRequest FromRequest for Result where T: FromRequest{ +impl FromRequest for Result +where + T: FromRequest, +{ type Config = T::Config; type Result = Box, Error = Error>>; #[inline] fn from_request(req: &HttpRequest, cfg: &Self::Config) -> Self::Result { - Box::new(T::from_request(req, cfg).into().then( |r| { future::ok(r) })) + Box::new(T::from_request(req, cfg).into().then(future::ok)) } } @@ -811,7 +813,10 @@ mod tests { let mut cfg = FormConfig::default(); cfg.limit(4096); - match Option::>::from_request(&req, &cfg).poll().unwrap() { + match Option::>::from_request(&req, &cfg) + .poll() + .unwrap() + { Async::Ready(r) => assert_eq!(r, None), _ => unreachable!(), } @@ -823,8 +828,16 @@ mod tests { .set_payload(Bytes::from_static(b"hello=world")) .finish(); - match Option::>::from_request(&req, &cfg).poll().unwrap() { - Async::Ready(r) => assert_eq!(r, Some(Form(Info { hello: "world".into() }))), + match Option::>::from_request(&req, &cfg) + .poll() + .unwrap() + { + Async::Ready(r) => assert_eq!( + r, + Some(Form(Info { + hello: "world".into() + })) + ), _ => unreachable!(), } @@ -835,7 +848,10 @@ mod tests { .set_payload(Bytes::from_static(b"bye=world")) .finish(); - match Option::>::from_request(&req, &cfg).poll().unwrap() { + match Option::>::from_request(&req, &cfg) + .poll() + .unwrap() + { Async::Ready(r) => assert_eq!(r, None), _ => unreachable!(), } @@ -850,8 +866,16 @@ mod tests { .set_payload(Bytes::from_static(b"hello=world")) .finish(); - match Result::, Error>::from_request(&req, &FormConfig::default()).poll().unwrap() { - Async::Ready(Ok(r)) => assert_eq!(r, Form(Info { hello: "world".into() })), + match Result::, Error>::from_request(&req, &FormConfig::default()) + .poll() + .unwrap() + { + Async::Ready(Ok(r)) => assert_eq!( + r, + Form(Info { + hello: "world".into() + }) + ), _ => unreachable!(), } @@ -862,14 +886,15 @@ mod tests { .set_payload(Bytes::from_static(b"bye=world")) .finish(); - match Result::, Error>::from_request(&req, &FormConfig::default()).poll().unwrap() { + match Result::, Error>::from_request(&req, &FormConfig::default()) + .poll() + .unwrap() + { Async::Ready(r) => assert!(r.is_err()), _ => unreachable!(), } } - - #[test] fn test_payload_config() { let req = TestRequest::default().finish();