diff --git a/examples/json/src/main.rs b/examples/json/src/main.rs index 5d074f935..6d85a35e8 100644 --- a/examples/json/src/main.rs +++ b/examples/json/src/main.rs @@ -31,7 +31,7 @@ fn index(req: HttpRequest) -> Box> { } /// This handler uses `With` helper for loading serde json object. -fn extract_item(_: &HttpRequest, item: Json) -> Result { +fn extract_item(_: HttpRequest, item: Json) -> Result { println!("model: {:?}", &item); httpcodes::HTTPOk.build().json(item.0) // <- send response } diff --git a/src/extractor.rs b/src/extractor.rs index c7eb558fb..a6373ab3f 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -33,7 +33,7 @@ pub trait HttpRequestExtractor: Sized where T: DeserializeOwned /// } /// /// /// extract path info using serde -/// fn index(req: &HttpRequest, info: Path) -> Result { +/// fn index(req: HttpRequest, info: Path) -> Result { /// Ok(format!("Welcome {}!", info.username)) /// } /// @@ -90,7 +90,7 @@ impl HttpRequestExtractor for Path where T: DeserializeOwned /// /// // use `with` extractor for query info /// // this handler get called only if request's query contains `username` field -/// fn index(req: &HttpRequest, info: Query) -> Result { +/// fn index(req: HttpRequest, info: Query) -> Result { /// Ok(format!("Welcome {}!", info.username)) /// } /// diff --git a/src/json.rs b/src/json.rs index 5687e75c5..94a3f368c 100644 --- a/src/json.rs +++ b/src/json.rs @@ -251,7 +251,7 @@ mod tests { #[test] fn test_with_json() { - let mut handler = with(|_: &_, data: Json| data); + let mut handler = with(|_: _, data: Json| data); let req = HttpRequest::default(); let mut json = handler.handle(req).into_future(); diff --git a/src/route.rs b/src/route.rs index 83879bce1..9f18cce51 100644 --- a/src/route.rs +++ b/src/route.rs @@ -127,7 +127,7 @@ impl Route { /// } /// /// /// extract path info using serde - /// fn index(req: &HttpRequest, info: Path) -> Result { + /// fn index(req: HttpRequest, info: Path) -> Result { /// Ok(format!("Welcome {}!", info.username)) /// } /// diff --git a/src/with.rs b/src/with.rs index b0cb0290e..a7b338a73 100644 --- a/src/with.rs +++ b/src/with.rs @@ -20,19 +20,19 @@ pub trait WithHandler: 'static type Result: Responder; /// Handle request - fn handle(&mut self, req: &HttpRequest, data: D) -> Self::Result; + fn handle(&mut self, req: HttpRequest, data: D) -> Self::Result; } /// WithHandler for Fn() impl WithHandler for F - where F: Fn(&HttpRequest, D) -> R + 'static, + where F: Fn(HttpRequest, D) -> R + 'static, R: Responder + 'static, D: HttpRequestExtractor, T: DeserializeOwned, { type Result = R; - fn handle(&mut self, req: &HttpRequest, item: D) -> R { + fn handle(&mut self, req: HttpRequest, item: D) -> R { (self)(req, item) } } @@ -114,7 +114,8 @@ impl Future for WithHandlerFut }; let hnd: &mut H = unsafe{&mut *self.hnd.get()}; - let item = match hnd.handle(&self.req, item).respond_to(self.req.without_state()) + let item = match hnd.handle(self.req.clone(), item) + .respond_to(self.req.without_state()) { Ok(item) => item.into(), Err(err) => return Err(err.into()),