1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-24 00:01:11 +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
pub struct FnNewServiceNoConfig<F, R, S, E>
where
@ -256,13 +266,13 @@ where
}
}
impl<F, C, R, S, E> IntoNewService<FnNewServiceConfig<F, C, R, S, E>, C> for F
where
F: Fn(&C) -> R,
R: IntoFuture<Item = S, Error = E>,
S: Service,
{
fn into_new_service(self) -> FnNewServiceConfig<F, C, R, S, E> {
FnNewServiceConfig::new(self)
}
}
// impl<F, C, R, S, E> IntoNewService<FnNewServiceConfig<F, C, R, S, E>, C> for F
// where
// F: Fn(&C) -> R,
// R: IntoFuture<Item = S, Error = E>,
// S: Service,
// {
// fn into_new_service(self) -> FnNewServiceConfig<F, C, R, S, E> {
// FnNewServiceConfig::new(self)
// }
// }

View File

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