diff --git a/examples/json/src/main.rs b/examples/json/src/main.rs index 5d074f93..6d85a35e 100644 --- a/examples/json/src/main.rs +++ b/examples/json/src/main.rs @@ -31,7 +31,7 @@ fn index(req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> { } /// This handler uses `With` helper for loading serde json object. -fn extract_item(_: &HttpRequest, item: Json<MyObj>) -> Result<HttpResponse> { +fn extract_item(_: HttpRequest, item: Json<MyObj>) -> Result<HttpResponse> { println!("model: {:?}", &item); httpcodes::HTTPOk.build().json(item.0) // <- send response } diff --git a/src/extractor.rs b/src/extractor.rs index c7eb558f..a6373ab3 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -33,7 +33,7 @@ pub trait HttpRequestExtractor<T>: Sized where T: DeserializeOwned /// } /// /// /// extract path info using serde -/// fn index(req: &HttpRequest, info: Path<Info>) -> Result<String> { +/// fn index(req: HttpRequest, info: Path<Info>) -> Result<String> { /// Ok(format!("Welcome {}!", info.username)) /// } /// @@ -90,7 +90,7 @@ impl<T> HttpRequestExtractor<T> for Path<T> 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<Info>) -> Result<String> { +/// fn index(req: HttpRequest, info: Query<Info>) -> Result<String> { /// Ok(format!("Welcome {}!", info.username)) /// } /// diff --git a/src/json.rs b/src/json.rs index 5687e75c..94a3f368 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<MyObject>| data); + let mut handler = with(|_: _, data: Json<MyObject>| data); let req = HttpRequest::default(); let mut json = handler.handle(req).into_future(); diff --git a/src/route.rs b/src/route.rs index 83879bce..9f18cce5 100644 --- a/src/route.rs +++ b/src/route.rs @@ -127,7 +127,7 @@ impl<S: 'static> Route<S> { /// } /// /// /// extract path info using serde - /// fn index(req: &HttpRequest, info: Path<Info>) -> Result<String> { + /// fn index(req: HttpRequest, info: Path<Info>) -> Result<String> { /// Ok(format!("Welcome {}!", info.username)) /// } /// diff --git a/src/with.rs b/src/with.rs index b0cb0290..a7b338a7 100644 --- a/src/with.rs +++ b/src/with.rs @@ -20,19 +20,19 @@ pub trait WithHandler<T, D, S>: 'static type Result: Responder; /// Handle request - fn handle(&mut self, req: &HttpRequest<S>, data: D) -> Self::Result; + fn handle(&mut self, req: HttpRequest<S>, data: D) -> Self::Result; } /// WithHandler<D, T, S> for Fn() impl<T, D, S, F, R> WithHandler<T, D, S> for F - where F: Fn(&HttpRequest<S>, D) -> R + 'static, + where F: Fn(HttpRequest<S>, D) -> R + 'static, R: Responder + 'static, D: HttpRequestExtractor<T>, T: DeserializeOwned, { type Result = R; - fn handle(&mut self, req: &HttpRequest<S>, item: D) -> R { + fn handle(&mut self, req: HttpRequest<S>, item: D) -> R { (self)(req, item) } } @@ -114,7 +114,8 @@ impl<T, D, S, H> Future for WithHandlerFut<T, D, S, H> }; 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()),