mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-25 06:36:02 +02:00
move state to request object
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use std::rc::Rc;
|
||||
use std::marker::PhantomData;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -64,7 +63,7 @@ impl<S> Resource<S> where S: 'static {
|
||||
|
||||
/// Register handler for specified method.
|
||||
pub fn handler<F, R>(&mut self, method: Method, handler: F)
|
||||
where F: Fn(HttpRequest, &S) -> Result<R> + 'static,
|
||||
where F: Fn(HttpRequest<S>) -> Result<R> + 'static,
|
||||
R: Into<HttpResponse> + 'static,
|
||||
{
|
||||
self.routes.insert(method, Box::new(FnHandler::new(handler)));
|
||||
@@ -72,7 +71,7 @@ impl<S> Resource<S> where S: 'static {
|
||||
|
||||
/// Register async handler for specified method.
|
||||
pub fn async<F, R>(&mut self, method: Method, handler: F)
|
||||
where F: Fn(HttpRequest, &S) -> R + 'static,
|
||||
where F: Fn(HttpRequest<S>) -> R + 'static,
|
||||
R: Stream<Item=Frame, Error=Error> + 'static,
|
||||
{
|
||||
self.routes.insert(method, Box::new(StreamHandler::new(handler)));
|
||||
@@ -125,11 +124,11 @@ impl<S> Resource<S> where S: 'static {
|
||||
|
||||
impl<S: 'static> RouteHandler<S> for Resource<S> {
|
||||
|
||||
fn handle(&self, req: HttpRequest, state: Rc<S>) -> Task {
|
||||
fn handle(&self, req: HttpRequest<S>) -> Task {
|
||||
if let Some(handler) = self.routes.get(req.method()) {
|
||||
handler.handle(req, state)
|
||||
handler.handle(req)
|
||||
} else {
|
||||
self.default.handle(req, state)
|
||||
self.default.handle(req)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user