mirror of
https://github.com/fafhrd91/actix-net
synced 2025-03-20 16:05:18 +01:00
add fn_nservice
This commit is contained in:
parent
43d2dd473f
commit
a0e2d926e6
@ -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>
|
pub struct FnNewService<F, Req, Out, Cfg>
|
||||||
where
|
where
|
||||||
F: FnMut(Req) -> Out,
|
F: FnMut(Req) -> Out,
|
||||||
@ -113,17 +122,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F, R, S, E> IntoNewService<FnNewServiceNoConfig<F, R, S, E>, ()> for F
|
/// Converter for `Fn() -> Future<Service>` fn
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct FnNewServiceNoConfig<F, R, S, E>
|
pub struct FnNewServiceNoConfig<F, R, S, E>
|
||||||
where
|
where
|
||||||
F: Fn() -> R + Clone,
|
F: Fn() -> R + Clone,
|
||||||
@ -173,3 +172,14 @@ where
|
|||||||
Self::new(self.f.clone())
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -24,7 +24,7 @@ use self::and_then_apply::{AndThenTransform, AndThenTransformNewService};
|
|||||||
use self::and_then_apply_fn::{AndThenApply, AndThenApplyNewService};
|
use self::and_then_apply_fn::{AndThenApply, AndThenApplyNewService};
|
||||||
pub use self::apply::{Apply, ApplyNewService};
|
pub use self::apply::{Apply, ApplyNewService};
|
||||||
pub use self::blank::{Blank, BlankNewService};
|
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::fn_transform::{FnNewTransform, FnTransform};
|
||||||
pub use self::from_err::{FromErr, FromErrNewService};
|
pub use self::from_err::{FromErr, FromErrNewService};
|
||||||
pub use self::map::{Map, MapNewService};
|
pub use self::map::{Map, MapNewService};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user