pub struct ThenFactory<A, B> { /* private fields */ }Expand description
Creates a Then service from two service factories.
Created by crate::ServiceChainFactory::then. Both factories use the
same state, service-error, and initialization-error types. The second
factory creates services whose request is the first service’s complete
Result, rather than just its successful response.
Creation is sequential with the same state reference. The second factory is invoked only after the first succeeds. An initialization error from either factory is returned unchanged; it is not passed to the second factory or handled as a service-call result.
Created services use the call and lifecycle behavior described in Then.
Wrap a child factory with crate::ready_factory() to give each of its
created services an independent readiness cache. Cloning clones both
factories without creating services.
§Example
use ntex_service::{factory, fn_factory, fn_service};
let factory = factory(fn_factory(async |_: &()| {
Ok::<_, &'static str>(fn_service(async |_: u32| Err::<u32, _>("unavailable")))
}))
.then(fn_factory(async |_: &()| {
Ok::<_, &'static str>(fn_service(async |result: Result<u32, &'static str>| {
Ok::<_, &'static str>(result.unwrap_or(42))
}))
}));
let pipeline = factory.pipeline(()).await?;
assert_eq!(pipeline.call(1).await?, 42);Trait Implementations§
Source§impl<A, B> Clone for ThenFactory<A, B>
impl<A, B> Clone for ThenFactory<A, B>
Source§fn clone(&self) -> ThenFactory<A, B>
fn clone(&self) -> ThenFactory<A, B>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<A, B> Debug for ThenFactory<A, B>
impl<A, B> Debug for ThenFactory<A, B>
Source§impl<A, B, St, Req> ServiceFactory<St, Req> for ThenFactory<A, B>where
A: ServiceFactory<St, Req>,
B: ServiceFactory<St, Result<<A as ServiceFactory<St, Req>>::Res, <A as ServiceFactory<St, Req>>::Error>, Error = <A as ServiceFactory<St, Req>>::Error, InitError = <A as ServiceFactory<St, Req>>::InitError>,
impl<A, B, St, Req> ServiceFactory<St, Req> for ThenFactory<A, B>where
A: ServiceFactory<St, Req>,
B: ServiceFactory<St, Result<<A as ServiceFactory<St, Req>>::Res, <A as ServiceFactory<St, Req>>::Error>, Error = <A as ServiceFactory<St, Req>>::Error, InitError = <A as ServiceFactory<St, Req>>::InitError>,
Source§type Res = <B as ServiceFactory<St, Result<<A as ServiceFactory<St, Req>>::Res, <A as ServiceFactory<St, Req>>::Error>>>::Res
type Res = <B as ServiceFactory<St, Result<<A as ServiceFactory<St, Req>>::Res, <A as ServiceFactory<St, Req>>::Error>>>::Res
Source§type Error = <A as ServiceFactory<St, Req>>::Error
type Error = <A as ServiceFactory<St, Req>>::Error
Source§type Service = Then<<A as ServiceFactory<St, Req>>::Service, <B as ServiceFactory<St, Result<<A as ServiceFactory<St, Req>>::Res, <A as ServiceFactory<St, Req>>::Error>>>::Service>
type Service = Then<<A as ServiceFactory<St, Req>>::Service, <B as ServiceFactory<St, Result<<A as ServiceFactory<St, Req>>::Res, <A as ServiceFactory<St, Req>>::Error>>>::Service>
Service produced by this factory.Source§type InitError = <A as ServiceFactory<St, Req>>::InitError
type InitError = <A as ServiceFactory<St, Req>>::InitError
Source§async fn create(
&self,
st: &St,
) -> Result<<ThenFactory<A, B> as ServiceFactory<St, Req>>::Service, <ThenFactory<A, B> as ServiceFactory<St, Req>>::InitError>
async fn create( &self, st: &St, ) -> Result<<ThenFactory<A, B> as ServiceFactory<St, Req>>::Service, <ThenFactory<A, B> as ServiceFactory<St, Req>>::InitError>
Source§async fn pipeline(
&self,
st: St,
) -> Result<Pipeline<Req, Self::Res, Self::Error>, Self::InitError>where
Self: 'static,
St: 'static,
Req: 'static,
async fn pipeline(
&self,
st: St,
) -> Result<Pipeline<Req, Self::Res, Self::Error>, Self::InitError>where
Self: 'static,
St: 'static,
Req: 'static,
Pipeline.