1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-20 20:55:51 +02:00

remove Applicaiton::route, resource is enough

This commit is contained in:
Nikolay Kim
2017-12-06 08:03:08 -08:00
parent 04ded5ba68
commit 87c7441f7d
11 changed files with 53 additions and 58 deletions

View File

@@ -3,7 +3,7 @@ use std::marker::PhantomData;
use http::Method;
use route::Route;
use handler::{Reply, Handler, RouteHandler, WrapHandler};
use handler::{Reply, Handler, FromRequest, RouteHandler, WrapHandler};
use httpcodes::HTTPNotFound;
use httprequest::HttpRequest;
@@ -79,17 +79,48 @@ impl<S> Resource<S> where S: 'static {
/// .f(|r| HttpResponse::Ok()))
/// .finish();
/// }
/// ```
pub fn route(&mut self) -> &mut Route<S> {
self.routes.push(Route::default());
self.routes.last_mut().unwrap()
}
/// Register a new route and add method check to route.
///
/// This is sortcut for:
/// ```rust,ignore
/// Resource::resource("/", |r| r.route().method(Method::GET).f(index)
/// ```
pub fn method(&mut self, method: Method) -> &mut Route<S> {
self.routes.push(Route::default());
self.routes.last_mut().unwrap().method(method)
}
/// Register a new route and add handler object.
///
/// This is sortcut for:
/// ```rust,ignore
/// Resource::resource("/", |r| r.route().h(handler)
/// ```
pub fn h<H: Handler<S>>(&mut self, handler: H) {
self.routes.push(Route::default());
self.routes.last_mut().unwrap().h(handler)
}
/// Register a new route and add handler function.
///
/// This is sortcut for:
/// ```rust,ignore
/// Resource::resource("/", |r| r.route().f(index)
/// ```
pub fn f<F, R>(&mut self, handler: F)
where F: Fn(HttpRequest<S>) -> R + 'static,
R: FromRequest + 'static,
{
self.routes.push(Route::default());
self.routes.last_mut().unwrap().f(handler)
}
/// Default handler is used if no matched route found.
/// By default `HTTPNotFound` is used.
pub fn default_handler<H>(&mut self, handler: H) where H: Handler<S> {