diff --git a/examples/diesel/src/main.rs b/examples/diesel/src/main.rs index e29f5dbc2..c05857c1a 100644 --- a/examples/diesel/src/main.rs +++ b/examples/diesel/src/main.rs @@ -37,15 +37,15 @@ struct State { fn index(req: HttpRequest) -> Box> { let name = &req.match_info()["name"]; - Box::new( - req.state().db.call_fut(CreateUser{name: name.to_owned()}) - .from_err() - .and_then(|res| { - match res { - Ok(user) => Ok(httpcodes::HTTPOk.build().json(user)?), - Err(_) => Ok(httpcodes::HTTPInternalServerError.response()) - } - })) + req.state().db.call_fut(CreateUser{name: name.to_owned()}) + .from_err() + .and_then(|res| { + match res { + Ok(user) => Ok(httpcodes::HTTPOk.build().json(user)?), + Err(_) => Ok(httpcodes::HTTPInternalServerError.response()) + } + }) + .responder() } fn main() { diff --git a/guide/src/qs_14.md b/guide/src/qs_14.md index 133d6d10a..0378c6b42 100644 --- a/guide/src/qs_14.md +++ b/guide/src/qs_14.md @@ -107,16 +107,16 @@ used for async handler registration. fn index(req: HttpRequest) -> Box> { let name = &req.match_info()["name"]; - Box::new( - // Send message to `DbExecutor` actor - req.state().db.call_fut(CreateUser{name: name.to_owned()}) - .and_then(|res| { - match res { - Ok(user) => ok(HTTPOk.build().json(user)), - Err(_) => ok(HTTPInternalServerError.response()) - } - }) - .map_err(|e| error::ErrorInternalServerError(e).into())) + // Send message to `DbExecutor` actor + req.state().db.call_fut(CreateUser{name: name.to_owned()}) + .from_err() + .and_then(|res| { + match res { + Ok(user) => Ok(httpcodes::HTTPOk.build().json(user)?), + Err(_) => Ok(httpcodes::HTTPInternalServerError.response()) + } + }) + .responder() } ``` diff --git a/guide/src/qs_7.md b/guide/src/qs_7.md index 3e321ff4d..7e341c889 100644 --- a/guide/src/qs_7.md +++ b/guide/src/qs_7.md @@ -234,14 +234,13 @@ use actix_web::*; use futures::future::{Future, ok}; fn index(mut req: HttpRequest) -> Box> { - Box::new( - req.urlencoded() // <- get UrlEncoded future - .and_then(|params| { // <- url encoded parameters - println!("==== BODY ==== {:?}", params); - ok(httpcodes::HTTPOk.response()) - }) - .map_err(Error::from) - ) + req.urlencoded() // <- get UrlEncoded future + .from_err() + .and_then(|params| { // <- url encoded parameters + println!("==== BODY ==== {:?}", params); + ok(httpcodes::HTTPOk.response()) + }) + .responder() } # fn main() {} ``` @@ -276,15 +275,15 @@ use futures::{Future, Stream}; fn index(mut req: HttpRequest) -> Box> { - Box::new( - req.payload_mut() - .readany() - .fold((), |_, chunk| { - println!("Chunk: {:?}", chunk); - result::<_, error::PayloadError>(Ok(())) - }) - .map_err(|e| Error::from(e)) - .map(|_| HttpResponse::Ok().finish().unwrap())) + req.payload_mut() + .readany() + .from_err() + .fold((), |_, chunk| { + println!("Chunk: {:?}", chunk); + result::<_, error::PayloadError>(Ok(())) + }) + .map(|_| HttpResponse::Ok().finish().unwrap()) + .responder() } # fn main() {} ``` diff --git a/src/httprequest.rs b/src/httprequest.rs index 3308d8513..dd28282be 100644 --- a/src/httprequest.rs +++ b/src/httprequest.rs @@ -456,14 +456,13 @@ impl HttpRequest { /// use futures::future::{Future, ok}; /// /// fn index(mut req: HttpRequest) -> Box> { - /// Box::new( - /// req.urlencoded() // <- get UrlEncoded future - /// .and_then(|params| { // <- url encoded parameters - /// println!("==== BODY ==== {:?}", params); - /// ok(httpcodes::HTTPOk.response()) - /// }) - /// .map_err(Error::from) - /// ) + /// req.urlencoded() // <- get UrlEncoded future + /// .from_err() + /// .and_then(|params| { // <- url encoded parameters + /// println!("==== BODY ==== {:?}", params); + /// ok(httpcodes::HTTPOk.response()) + /// }) + /// .responder() /// } /// # fn main() {} /// ```