1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 17:07:01 +02:00

refactor Handler trait, use mut self

This commit is contained in:
Nikolay Kim
2017-12-26 09:00:45 -08:00
parent b61a07a320
commit cf8c2ca95e
14 changed files with 138 additions and 59 deletions

View File

@@ -15,8 +15,8 @@ use httprequest::HttpRequest;
use httpresponse::HttpResponse;
use middlewares::{Middleware, Finished, Started, Response};
type Handler<S> = Fn(HttpRequest<S>) -> Reply;
pub(crate) type PipelineHandler<'a, S> = &'a Fn(HttpRequest<S>) -> Reply;
type Handler<S> = FnMut(HttpRequest<S>) -> Reply;
pub(crate) type PipelineHandler<'a, S> = &'a mut FnMut(HttpRequest<S>) -> Reply;
pub struct Pipeline<S>(PipelineInfo<S>, PipelineState<S>);
@@ -287,7 +287,7 @@ impl<S> StartMiddlewares<S> {
let len = info.mws.len();
loop {
if info.count == len {
let reply = (&*handler)(info.req.clone());
let reply = (&mut *handler)(info.req.clone());
return WaitingResponse::init(info, reply)
} else {
match info.mws[info.count].start(&mut info.req) {
@@ -329,7 +329,7 @@ impl<S> StartMiddlewares<S> {
return Ok(RunMiddlewares::init(info, resp));
}
if info.count == len {
let reply = (unsafe{&*self.hnd})(info.req.clone());
let reply = (unsafe{&mut *self.hnd})(info.req.clone());
return Ok(WaitingResponse::init(info, reply));
} else {
loop {