From 0745a1a9f8d43840454c6aae24df5e2c6f781c36 Mon Sep 17 00:00:00 2001 From: Douman Date: Wed, 5 Dec 2018 03:07:59 -0500 Subject: [PATCH] Remove usage of upcoming keyword async AsyncResult::async is replaced with AsyncResult::future --- CHANGES.md | 2 ++ MIGRATION.md | 2 ++ src/client/connector.rs | 2 +- src/client/request.rs | 2 +- src/handler.rs | 6 +++--- src/middleware/csrf.rs | 2 +- src/route.rs | 2 +- src/scope.rs | 2 +- src/with.rs | 4 ++-- 9 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 902a84f69..4d8fa128f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,8 @@ * `QueryConfig` and `PathConfig` are made public. +* `AsyncResult::async` is changed to `AsyncResult::future` as `async` is reserved keyword in 2018 edition. + ### Added * By default, `Path` extractor now percent decode all characters. This behaviour can be disabled diff --git a/MIGRATION.md b/MIGRATION.md index 26a314240..6b49e3e6a 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -25,6 +25,8 @@ } ``` +* If you used `AsyncResult::async` you need to replace it with `AsyncResult::future` + ## 0.7.4 diff --git a/src/client/connector.rs b/src/client/connector.rs index 72132bc67..f5affad37 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -942,7 +942,7 @@ impl Handler for ClientConnector { } let host = uri.host().unwrap().to_owned(); - let port = uri.port().unwrap_or_else(|| proto.port()); + let port = uri.port_part().map(|port| port.as_u16()).unwrap_or_else(|| proto.port()); let key = Key { host, port, diff --git a/src/client/request.rs b/src/client/request.rs index 76fb1be59..71da8f74d 100644 --- a/src/client/request.rs +++ b/src/client/request.rs @@ -631,7 +631,7 @@ impl ClientRequestBuilder { if !parts.headers.contains_key(header::HOST) { let mut wrt = BytesMut::with_capacity(host.len() + 5).writer(); - let _ = match parts.uri.port() { + let _ = match parts.uri.port_part().map(|port| port.as_u16()) { None | Some(80) | Some(443) => write!(wrt, "{}", host), Some(port) => write!(wrt, "{}:{}", host, port), }; diff --git a/src/handler.rs b/src/handler.rs index 88210fbc0..6ed93f92e 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -250,7 +250,7 @@ pub(crate) enum AsyncResultItem { impl AsyncResult { /// Create async response #[inline] - pub fn async(fut: Box>) -> AsyncResult { + pub fn future(fut: Box>) -> AsyncResult { AsyncResult(Some(AsyncResultItem::Future(fut))) } @@ -401,7 +401,7 @@ where }, Err(e) => err(e), }); - Ok(AsyncResult::async(Box::new(fut))) + Ok(AsyncResult::future(Box::new(fut))) } } @@ -502,7 +502,7 @@ where Err(e) => Either::A(err(e)), } }); - AsyncResult::async(Box::new(fut)) + AsyncResult::future(Box::new(fut)) } } diff --git a/src/middleware/csrf.rs b/src/middleware/csrf.rs index 02cd150d5..cacfc8d53 100644 --- a/src/middleware/csrf.rs +++ b/src/middleware/csrf.rs @@ -76,7 +76,7 @@ impl ResponseError for CsrfError { } fn uri_origin(uri: &Uri) -> Option { - match (uri.scheme_part(), uri.host(), uri.port()) { + match (uri.scheme_part(), uri.host(), uri.port_part().map(|port| port.as_u16())) { (Some(scheme), Some(host), Some(port)) => { Some(format!("{}://{}:{}", scheme, host, port)) } diff --git a/src/route.rs b/src/route.rs index e4a7a9572..884a367ed 100644 --- a/src/route.rs +++ b/src/route.rs @@ -57,7 +57,7 @@ impl Route { pub(crate) fn compose( &self, req: HttpRequest, mws: Rc>>>, ) -> AsyncResult { - AsyncResult::async(Box::new(Compose::new(req, mws, self.handler.clone()))) + AsyncResult::future(Box::new(Compose::new(req, mws, self.handler.clone()))) } /// Add match predicate to route. diff --git a/src/scope.rs b/src/scope.rs index 1bddc0e01..fb9e7514a 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -356,7 +356,7 @@ impl RouteHandler for Scope { if self.middlewares.is_empty() { self.router.handle(&req2) } else { - AsyncResult::async(Box::new(Compose::new( + AsyncResult::future(Box::new(Compose::new( req2, Rc::clone(&self.router), Rc::clone(&self.middlewares), diff --git a/src/with.rs b/src/with.rs index c6d54dee8..140e086e1 100644 --- a/src/with.rs +++ b/src/with.rs @@ -86,7 +86,7 @@ where match fut.poll() { Ok(Async::Ready(resp)) => AsyncResult::ok(resp), - Ok(Async::NotReady) => AsyncResult::async(Box::new(fut)), + Ok(Async::NotReady) => AsyncResult::future(Box::new(fut)), Err(e) => AsyncResult::err(e), } } @@ -208,7 +208,7 @@ where match fut.poll() { Ok(Async::Ready(resp)) => AsyncResult::ok(resp), - Ok(Async::NotReady) => AsyncResult::async(Box::new(fut)), + Ok(Async::NotReady) => AsyncResult::future(Box::new(fut)), Err(e) => AsyncResult::err(e), } }