1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 23:51:06 +01:00

use Result intead of HandlerResult

This commit is contained in:
Nikolay Kim 2017-11-18 06:50:07 -10:00
parent c800bf55f5
commit a87784ba15
4 changed files with 6 additions and 9 deletions

View File

@ -5,6 +5,7 @@ extern crate env_logger;
extern crate futures; extern crate futures;
use actix_web::*; use actix_web::*;
use actix_web::error::Result;
use futures::stream::{once, Once}; use futures::stream::{once, Once};
/// somple handle /// somple handle
@ -32,8 +33,7 @@ fn index_async(req: &mut HttpRequest, _payload: Payload, state: &())
} }
/// handle with path parameters like `/user/{name}/` /// handle with path parameters like `/user/{name}/`
fn with_param(req: &mut HttpRequest, _payload: Payload, state: &()) fn with_param(req: &mut HttpRequest, _payload: Payload, state: &()) -> Result<HttpResponse>
-> HandlerResult<HttpResponse>
{ {
println!("{:?}", req); println!("{:?}", req);

View File

@ -133,7 +133,7 @@ impl<T, H> Http2<T, H>
entry.task.disconnected() entry.task.disconnected()
} }
}, },
Ok(Async::Ready(Some((mut req, resp)))) => { Ok(Async::Ready(Some((req, resp)))) => {
not_ready = false; not_ready = false;
let (parts, body) = req.into_parts(); let (parts, body) = req.into_parts();

View File

@ -77,7 +77,7 @@ pub use httprequest::{HttpRequest, UrlEncoded};
pub use httpresponse::{HttpResponse, HttpResponseBuilder}; pub use httpresponse::{HttpResponse, HttpResponseBuilder};
pub use payload::{Payload, PayloadItem}; pub use payload::{Payload, PayloadItem};
pub use route::{Frame, Route, RouteFactory, RouteHandler, RouteResult}; pub use route::{Frame, Route, RouteFactory, RouteHandler, RouteResult};
pub use resource::{Reply, Resource, HandlerResult}; pub use resource::{Reply, Resource};
pub use recognizer::{Params, RouteRecognizer}; pub use recognizer::{Params, RouteRecognizer};
pub use server::HttpServer; pub use server::HttpServer;
pub use context::HttpContext; pub use context::HttpContext;

View File

@ -8,7 +8,7 @@ use http::Method;
use futures::Stream; use futures::Stream;
use task::Task; use task::Task;
use error::Error; use error::{Result, Error};
use route::{Route, RouteHandler, RouteResult, Frame, FnHandler, StreamHandler}; use route::{Route, RouteHandler, RouteResult, Frame, FnHandler, StreamHandler};
use payload::Payload; use payload::Payload;
use context::HttpContext; use context::HttpContext;
@ -16,9 +16,6 @@ use httprequest::HttpRequest;
use httpresponse::HttpResponse; use httpresponse::HttpResponse;
use httpcodes::{HTTPNotFound, HTTPMethodNotAllowed}; use httpcodes::{HTTPNotFound, HTTPMethodNotAllowed};
/// Result of a resource handler function
pub type HandlerResult<T> = Result<T, Error>;
/// Http resource /// Http resource
/// ///
/// `Resource` is an entry in route table which corresponds to requested URL. /// `Resource` is an entry in route table which corresponds to requested URL.
@ -69,7 +66,7 @@ impl<S> Resource<S> where S: 'static {
/// Register handler for specified method. /// Register handler for specified method.
pub fn handler<F, R>(&mut self, method: Method, handler: F) pub fn handler<F, R>(&mut self, method: Method, handler: F)
where F: Fn(&mut HttpRequest, Payload, &S) -> HandlerResult<R> + 'static, where F: Fn(&mut HttpRequest, Payload, &S) -> Result<R> + 'static,
R: Into<HttpResponse> + 'static, R: Into<HttpResponse> + 'static,
{ {
self.routes.insert(method, Box::new(FnHandler::new(handler))); self.routes.insert(method, Box::new(FnHandler::new(handler)));