diff --git a/src/service/make_service.rs b/src/service/make_service.rs index f694e30cc5..0472d2f983 100644 --- a/src/service/make_service.rs +++ b/src/service/make_service.rs @@ -115,7 +115,7 @@ where /// ``` pub fn make_service_fn(f: F) -> MakeServiceFn where - F: Fn(&Ctx) -> Ret, + F: FnMut(&Ctx) -> Ret, Ret: IntoFuture, { MakeServiceFn { @@ -130,7 +130,7 @@ pub struct MakeServiceFn { impl<'c, F, Ctx, Ret, ReqBody, ResBody> MakeService<&'c Ctx> for MakeServiceFn where - F: Fn(&Ctx) -> Ret, + F: FnMut(&Ctx) -> Ret, Ret: IntoFuture, Ret::Item: Service, Ret::Error: Into>, diff --git a/src/service/service.rs b/src/service/service.rs index 0f9d7e2020..53d3e166c9 100644 --- a/src/service/service.rs +++ b/src/service/service.rs @@ -51,7 +51,7 @@ pub trait Service { /// ``` pub fn service_fn(f: F) -> ServiceFn where - F: Fn(Request) -> S, + F: FnMut(Request) -> S, S: IntoFuture, { ServiceFn { @@ -75,7 +75,7 @@ where /// ``` pub fn service_fn_ok(f: F) -> ServiceFnOk where - F: Fn(Request) -> Response, + F: FnMut(Request) -> Response, S: Payload, { ServiceFnOk { @@ -92,7 +92,7 @@ pub struct ServiceFn { impl Service for ServiceFn where - F: Fn(Request) -> Ret, + F: FnMut(Request) -> Ret, ReqBody: Payload, Ret: IntoFuture>, Ret::Error: Into>, @@ -133,7 +133,7 @@ pub struct ServiceFnOk { impl Service for ServiceFnOk where - F: Fn(Request) -> Response, + F: FnMut(Request) -> Response, ReqBody: Payload, ResBody: Payload, { @@ -163,3 +163,24 @@ impl fmt::Debug for ServiceFnOk { .finish() } } + +//#[cfg(test)] +fn _assert_fn_mut() { + fn assert_service(_t: &T) {} + + let mut val = 0; + + let svc = service_fn(move |_req: Request<::Body>| { + val += 1; + future::ok::<_, Never>(Response::new(::Body::empty())) + }); + + assert_service(&svc); + + let svc = service_fn_ok(move |_req: Request<::Body>| { + val += 1; + Response::new(::Body::empty()) + }); + + assert_service(&svc); +}