mirror of
https://github.com/actix/actix-website
synced 2025-01-23 00:25:55 +01:00
commit
0b003828b3
@ -29,9 +29,11 @@ fn index(params: Path<(String, String,)>, info: Json<MyInfo>) -> HttpResponse {
|
|||||||
|
|
||||||
// Option 2: accessed by calling extract() on the Extractor
|
// Option 2: accessed by calling extract() on the Extractor
|
||||||
|
|
||||||
|
use actix_web::FromRequest;
|
||||||
|
|
||||||
fn index(req: HttpRequest) -> HttpResponse {
|
fn index(req: HttpRequest) -> HttpResponse {
|
||||||
let params = Path::<(String, String)>::extract(req);
|
let params = Path::<(String, String)>::extract(&req);
|
||||||
let info = Json::<MyInfo>::extract(req);
|
let info = Json::<MyInfo>::extract(&req);
|
||||||
|
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
@ -40,7 +42,7 @@ fn index(req: HttpRequest) -> HttpResponse {
|
|||||||
## Within Custom Handler Types
|
## Within Custom Handler Types
|
||||||
|
|
||||||
Like a handler function, a custom Handler type can *access* an Extractor by
|
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
|
*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 type must follow the ``handle`` function signature specified by the
|
||||||
Handler trait it implements.
|
Handler trait it implements.
|
||||||
@ -54,8 +56,8 @@ impl<S> Handler<S> for MyHandler {
|
|||||||
|
|
||||||
/// Handle request
|
/// Handle request
|
||||||
fn handle(&mut self, req: HttpRequest<S>) -> Self::Result {
|
fn handle(&mut self, req: HttpRequest<S>) -> Self::Result {
|
||||||
let params = Path::<(String, String)>::extract(req);
|
let params = Path::<(String, String)>::extract(&req);
|
||||||
let info = Json::<MyInfo>::extract(req);
|
let info = Json::<MyInfo>::extract(&req);
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user