From 1019dd2fb468efa336cd578ac4da88705b87d658 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 28 May 2018 20:55:13 +0200 Subject: [PATCH] Improve extractor examples To use `SomeType::extract(&req)` it should be mentioned at least once that `use actix_web::FromRequest` is required. Also extract takes `HttpRequest` by reference. --- content/docs/extractors.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/content/docs/extractors.md b/content/docs/extractors.md index ee56600..2a2a298 100644 --- a/content/docs/extractors.md +++ b/content/docs/extractors.md @@ -29,9 +29,11 @@ fn index(params: Path<(String, String,)>, info: Json) -> HttpResponse { // Option 2: accessed by calling extract() on the Extractor +use actix_web::FromRequest; + fn index(req: HttpRequest) -> HttpResponse { - let params = Path::<(String, String)>::extract(req); - let info = Json::::extract(req); + let params = Path::<(String, String)>::extract(&req); + let info = Json::::extract(&req); ... } @@ -40,7 +42,7 @@ fn index(req: HttpRequest) -> HttpResponse { ## Within Custom Handler Types Like a handler function, a custom Handler type can *access* an Extractor by -calling the ExtractorType::<...>::extract(req) function. An Extractor +calling the ExtractorType::<...>::extract(&req) function. An Extractor *cannot* be passed as a parameter to a custom Handler type because a custom Handler type must follow the ``handle`` function signature specified by the Handler trait it implements. @@ -54,8 +56,8 @@ impl Handler for MyHandler { /// Handle request fn handle(&mut self, req: HttpRequest) -> Self::Result { - let params = Path::<(String, String)>::extract(req); - let info = Json::::extract(req); + let params = Path::<(String, String)>::extract(&req); + let info = Json::::extract(&req); ...