From b55d69b4c25ce8ac1a8f7938dbca07ad5bcf846d Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 28 Nov 2017 12:42:53 -0800 Subject: [PATCH] better handler result handling --- examples/basic.rs | 8 ++++---- src/application.rs | 4 +--- src/httpresponse.rs | 4 ++-- tests/test_server.rs | 8 ++------ 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/examples/basic.rs b/examples/basic.rs index ff8cf744e..2b6076fd6 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -78,10 +78,10 @@ fn main() { .resource("/", |r| r.handler(Method::GET, |req| { println!("{:?}", req); - Ok(httpcodes::HTTPFound - .build() - .header("LOCATION", "/index.html") - .body(Body::Empty)?) + httpcodes::HTTPFound + .build() + .header("LOCATION", "/index.html") + .body(Body::Empty) })) // static files .route_handler("/static", StaticFiles::new("examples/static/", true))) diff --git a/src/application.rs b/src/application.rs index 8912438c2..b12019d53 100644 --- a/src/application.rs +++ b/src/application.rs @@ -148,9 +148,7 @@ impl ApplicationBuilder where S: 'static { /// let app = Application::default("/") /// .resource("/test", |r| { /// r.get::(); - /// r.handler(Method::HEAD, |req| { - /// Ok(httpcodes::HTTPMethodNotAllowed) - /// }); + /// r.handler(Method::HEAD, |req| httpcodes::HTTPMethodNotAllowed); /// }) /// .finish(); /// } diff --git a/src/httpresponse.rs b/src/httpresponse.rs index 1c9877fb9..91b2b1350 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -205,11 +205,11 @@ impl HttpResponse { } /// Helper conversion implementation -impl, E: Into> From> for HttpResponse { +impl, E: Into> From> for HttpResponse { fn from(res: Result) -> Self { match res { Ok(val) => val.into(), - Err(err) => err.into(), + Err(err) => err.into().into(), } } } diff --git a/tests/test_server.rs b/tests/test_server.rs index 83f94ce4b..445536dd4 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -16,9 +16,7 @@ fn create_server() -> HttpServer> { HttpServer::new( vec![Application::default("/") .resource("/", |r| - r.handler(Method::GET, |_| { - Ok(httpcodes::HTTPOk) - })) + r.handler(Method::GET, |_| httpcodes::HTTPOk)) .finish()]) } @@ -96,9 +94,7 @@ fn test_middlewares() { response: act_num2, finish: act_num3}) .resource("/", |r| - r.handler(Method::GET, |_| { - Ok(httpcodes::HTTPOk) - })) + r.handler(Method::GET, |_| httpcodes::HTTPOk)) .finish()]) .serve::<_, ()>("127.0.0.1:58904").unwrap(); sys.run();