1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 22:32:57 +01:00

add IntoNewService for FnNewService

This commit is contained in:
Nikolay Kim 2019-02-22 14:19:43 -08:00
parent d2bd9134aa
commit 6b4010892d
2 changed files with 21 additions and 11 deletions

View File

@ -142,6 +142,16 @@ where
} }
} }
impl<F, Req, Out, Cfg> IntoNewService<FnNewService<F, Req, Out, Cfg>, Cfg> for F
where
F: Fn(Req) -> Out + Clone,
Out: IntoFuture,
{
fn into_new_service(self) -> FnNewService<F, Req, Out, Cfg> {
FnNewService::new(self)
}
}
/// Converter for `Fn() -> Future<Service>` fn /// Converter for `Fn() -> Future<Service>` fn
pub struct FnNewServiceNoConfig<F, R, S, E> pub struct FnNewServiceNoConfig<F, R, S, E>
where where
@ -256,13 +266,13 @@ where
} }
} }
impl<F, C, R, S, E> IntoNewService<FnNewServiceConfig<F, C, R, S, E>, C> for F // impl<F, C, R, S, E> IntoNewService<FnNewServiceConfig<F, C, R, S, E>, C> for F
where // where
F: Fn(&C) -> R, // F: Fn(&C) -> R,
R: IntoFuture<Item = S, Error = E>, // R: IntoFuture<Item = S, Error = E>,
S: Service, // S: Service,
{ // {
fn into_new_service(self) -> FnNewServiceConfig<F, C, R, S, E> { // fn into_new_service(self) -> FnNewServiceConfig<F, C, R, S, E> {
FnNewServiceConfig::new(self) // FnNewServiceConfig::new(self)
} // }
} // }

View File

@ -229,7 +229,7 @@ mod tests {
#[test] #[test]
fn test_new_service() { fn test_new_service() {
let blank = |_: &()| Ok::<_, ()>(Srv); let blank = || Ok::<_, ()>(Srv);
let new_srv = blank.into_new_service().map_err(|_| "error"); let new_srv = blank.into_new_service().map_err(|_| "error");
if let Async::Ready(mut srv) = new_srv.new_service(&()).poll().unwrap() { if let Async::Ready(mut srv) = new_srv.new_service(&()).poll().unwrap() {
let res = srv.call(()).poll(); let res = srv.call(()).poll();