diff --git a/examples/basics/src/main.rs b/examples/basics/src/main.rs index 6c82f8769..7e1bc1c4f 100644 --- a/examples/basics/src/main.rs +++ b/examples/basics/src/main.rs @@ -51,7 +51,7 @@ fn index(mut req: HttpRequest) -> Result { // response Ok(HttpResponse::build(StatusCode::OK) .content_type("text/html; charset=utf-8") - .body(&html).unwrap()) + .body(&html)) } @@ -69,7 +69,7 @@ fn p404(req: HttpRequest) -> Result { // response Ok(HttpResponse::build(StatusCode::NOT_FOUND) .content_type("text/html; charset=utf-8") - .body(html).unwrap()) + .body(html)) } @@ -78,20 +78,19 @@ fn index_async(req: HttpRequest) -> FutureResult { println!("{:?}", req); - result(HttpResponse::Ok() - .content_type("text/html") - .body(format!("Hello {}!", req.match_info().get("name").unwrap())) - .map_err(|e| e.into())) + result(Ok(HttpResponse::Ok() + .content_type("text/html") + .body(format!("Hello {}!", req.match_info().get("name").unwrap())))) } /// handler with path parameters like `/user/{name}/` -fn with_param(req: HttpRequest) -> Result +fn with_param(req: HttpRequest) -> HttpResponse { println!("{:?}", req); - Ok(HttpResponse::Ok() - .content_type("test/plain") - .body(format!("Hello {}!", req.match_info().get("name").unwrap()))?) + HttpResponse::Ok() + .content_type("test/plain") + .body(format!("Hello {}!", req.match_info().get("name").unwrap())) } fn main() { diff --git a/examples/diesel/src/main.rs b/examples/diesel/src/main.rs index 6a28107af..76ba2d39f 100644 --- a/examples/diesel/src/main.rs +++ b/examples/diesel/src/main.rs @@ -44,7 +44,7 @@ fn index(req: HttpRequest) -> Box> .from_err() .and_then(|res| { match res { - Ok(user) => Ok(HttpResponse::Ok().json(user)?), + Ok(user) => Ok(HttpResponse::Ok().json(user)), Err(_) => Ok(HttpResponse::InternalServerError().into()) } }) diff --git a/examples/http-proxy/src/main.rs b/examples/http-proxy/src/main.rs index 494351abb..73c91c0af 100644 --- a/examples/http-proxy/src/main.rs +++ b/examples/http-proxy/src/main.rs @@ -18,9 +18,7 @@ fn index(_req: HttpRequest) -> Box> { |resp| resp.body() // <- this is MessageBody type, resolves to complete body .from_err() // <- convert PayloadError to a Error .and_then(|body| { // <- we got complete body, now send as server response - HttpResponse::Ok() - .body(body) - .map_err(Error::from) + Ok(HttpResponse::Ok().body(body)) })) .responder() } @@ -33,11 +31,10 @@ fn streaming(_req: HttpRequest) -> Box> { .send() // <- connect to host and send request .map_err(Error::from) // <- convert SendRequestError to an Error .and_then(|resp| { // <- we received client response - HttpResponse::Ok() - // read one chunk from client response and send this chunk to a server response - // .from_err() converts PayloadError to a Error - .body(Body::Streaming(Box::new(resp.from_err()))) - .map_err(|e| e.into()) // HttpOk::build() maybe return HttpError, we need to convert it to a Error + Ok(HttpResponse::Ok() + // read one chunk from client response and send this chunk to a server response + // .from_err() converts PayloadError to a Error + .body(Body::Streaming(Box::new(resp.from_err())))) }) .responder() } diff --git a/examples/json/src/main.rs b/examples/json/src/main.rs index 40891d319..f92909fef 100644 --- a/examples/json/src/main.rs +++ b/examples/json/src/main.rs @@ -27,13 +27,13 @@ fn index(req: HttpRequest) -> Box> { .from_err() // convert all errors into `Error` .and_then(|val: MyObj| { println!("model: {:?}", val); - Ok(HttpResponse::Ok().json(val)?) // <- send response + Ok(HttpResponse::Ok().json(val)) // <- send response }) .responder() } /// This handler uses `With` helper for loading serde json object. -fn extract_item(item: Json) -> Result { +fn extract_item(item: Json) -> HttpResponse { println!("model: {:?}", &item); HttpResponse::Ok().json(item.0) // <- send response } @@ -64,7 +64,7 @@ fn index_manual(req: HttpRequest) -> Box> .and_then(|body| { // body is loaded, now we can deserialize serde-json let obj = serde_json::from_slice::(&body)?; - Ok(HttpResponse::Ok().json(obj)?) // <- send response + Ok(HttpResponse::Ok().json(obj)) // <- send response }) .responder() } @@ -79,7 +79,7 @@ fn index_mjsonrust(req: HttpRequest) -> Box v, Err(e) => object!{"err" => e.to_string() } }; Ok(HttpResponse::Ok() .content_type("application/json") - .body(injson.dump()).unwrap()) + .body(injson.dump())) }) .responder() } diff --git a/examples/juniper/src/main.rs b/examples/juniper/src/main.rs index a377b581e..a627425e1 100644 --- a/examples/juniper/src/main.rs +++ b/examples/juniper/src/main.rs @@ -67,7 +67,7 @@ fn graphiql(_req: HttpRequest) -> Result { let html = graphiql_source("http://127.0.0.1:8080/graphql"); Ok(HttpResponse::Ok() .content_type("text/html; charset=utf-8") - .body(html).unwrap()) + .body(html)) } fn graphql(req: HttpRequest) -> Box> { @@ -79,7 +79,7 @@ fn graphql(req: HttpRequest) -> Box Ok(HttpResponse::Ok().body(user)?), + Ok(user) => Ok(HttpResponse::Ok().body(user)), Err(_) => Ok(HttpResponse::InternalServerError().into()) } }) diff --git a/examples/protobuf/src/protobuf.rs b/examples/protobuf/src/protobuf.rs index c06c191fd..2b117fe76 100644 --- a/examples/protobuf/src/protobuf.rs +++ b/examples/protobuf/src/protobuf.rs @@ -163,6 +163,6 @@ impl ProtoBufResponseBuilder for HttpResponseBuilder { let mut body = Vec::new(); value.encode(&mut body).map_err(|e| ProtoBufPayloadError::Serialize(e))?; - Ok(self.body(body)?) + Ok(self.body(body)) } } diff --git a/examples/r2d2/src/main.rs b/examples/r2d2/src/main.rs index 117675b89..528b4f200 100644 --- a/examples/r2d2/src/main.rs +++ b/examples/r2d2/src/main.rs @@ -34,7 +34,7 @@ fn index(req: HttpRequest) -> Box> .from_err() .and_then(|res| { match res { - Ok(user) => Ok(HttpResponse::Ok().json(user)?), + Ok(user) => Ok(HttpResponse::Ok().json(user)), Err(_) => Ok(HttpResponse::InternalServerError().into()) } }) diff --git a/examples/state/src/main.rs b/examples/state/src/main.rs index b9d1206da..7bd5f443a 100644 --- a/examples/state/src/main.rs +++ b/examples/state/src/main.rs @@ -11,8 +11,7 @@ use std::cell::Cell; use actix::prelude::*; use actix_web::{ - http, server, ws, middleware, - Application, HttpRequest, HttpResponse, Error}; + http, server, ws, middleware, Application, HttpRequest, HttpResponse}; /// Application state struct AppState { @@ -20,7 +19,7 @@ struct AppState { } /// simple handle -fn index(req: HttpRequest) -> Result { +fn index(req: HttpRequest) -> HttpResponse { println!("{:?}", req); req.state().counter.set(req.state().counter.get() + 1); diff --git a/examples/template_tera/src/main.rs b/examples/template_tera/src/main.rs index 7876a9163..e10072553 100644 --- a/examples/template_tera/src/main.rs +++ b/examples/template_tera/src/main.rs @@ -27,7 +27,7 @@ fn index(req: HttpRequest) -> Result { }; Ok(HttpResponse::Ok() .content_type("text/html") - .body(s)?) + .body(s)) } fn main() { diff --git a/examples/tls/src/main.rs b/examples/tls/src/main.rs index 3f696f41c..8fa00abcc 100644 --- a/examples/tls/src/main.rs +++ b/examples/tls/src/main.rs @@ -15,7 +15,7 @@ fn index(req: HttpRequest) -> Result { println!("{:?}", req); Ok(HttpResponse::Ok() .content_type("text/plain") - .body("Welcome!")?) + .body("Welcome!")) } fn main() { diff --git a/examples/web-cors/backend/src/user.rs b/examples/web-cors/backend/src/user.rs index 281c14453..364430fce 100644 --- a/examples/web-cors/backend/src/user.rs +++ b/examples/web-cors/backend/src/user.rs @@ -1,4 +1,4 @@ -use actix_web::{Error, HttpMessage, HttpResponse, HttpRequest}; +use actix_web::{AsyncResponder, Error, HttpMessage, HttpResponse, HttpRequest}; use futures::Future;