1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 21:51:06 +01:00

add fn_nservice

This commit is contained in:
Nikolay Kim 2019-02-22 13:20:52 -08:00
parent 43d2dd473f
commit a0e2d926e6
2 changed files with 22 additions and 12 deletions

View File

@ -66,6 +66,15 @@ where
}
}
/// Create `NewService` for function that can act as Service
pub fn fn_nservice<F, Req, Out>(f: F) -> FnNewService<F, Req, Out, ()>
where
F: FnMut(Req) -> Out + Clone,
Out: IntoFuture,
{
FnNewService::new(f)
}
pub struct FnNewService<F, Req, Out, Cfg>
where
F: FnMut(Req) -> Out,
@ -113,17 +122,7 @@ where
}
}
impl<F, R, S, E> IntoNewService<FnNewServiceNoConfig<F, R, S, E>, ()> for F
where
F: Fn() -> R + Clone,
R: IntoFuture<Item = S, Error = E>,
S: Service,
{
fn into_new_service(self) -> FnNewServiceNoConfig<F, R, S, E> {
FnNewServiceNoConfig::new(self)
}
}
/// Converter for `Fn() -> Future<Service>` fn
pub struct FnNewServiceNoConfig<F, R, S, E>
where
F: Fn() -> R + Clone,
@ -173,3 +172,14 @@ where
Self::new(self.f.clone())
}
}
impl<F, R, S, E> IntoNewService<FnNewServiceNoConfig<F, R, S, E>, ()> for F
where
F: Fn() -> R + Clone,
R: IntoFuture<Item = S, Error = E>,
S: Service,
{
fn into_new_service(self) -> FnNewServiceNoConfig<F, R, S, E> {
FnNewServiceNoConfig::new(self)
}
}

View File

@ -24,7 +24,7 @@ use self::and_then_apply::{AndThenTransform, AndThenTransformNewService};
use self::and_then_apply_fn::{AndThenApply, AndThenApplyNewService};
pub use self::apply::{Apply, ApplyNewService};
pub use self::blank::{Blank, BlankNewService};
pub use self::fn_service::{FnNewService, FnService};
pub use self::fn_service::{fn_nservice, FnNewService, FnService};
pub use self::fn_transform::{FnNewTransform, FnTransform};
pub use self::from_err::{FromErr, FromErrNewService};
pub use self::map::{Map, MapNewService};