pub struct AndThenFactory<A, B> { /* private fields */ }Expand description
Creates an AndThen service from two service factories.
Created by ServiceFactory::and_then,
crate::ServiceChainFactory::and_then, or Self::new.
Both factories use the same state, service-error, and initialization-error
types. The first factory’s response type is the second factory’s request
type.
Creation is sequential: the first factory completes before the second starts, and both receive the same state reference. If the first factory fails, the second is not invoked. Initialization errors from either factory are returned unchanged.
Created services use the call, binding, readiness, and shutdown behavior
described in AndThen. 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 any services.
Implementations§
Source§impl<A, B> AndThenFactory<A, B>
impl<A, B> AndThenFactory<A, B>
Sourcepub fn new(svc1: A, svc2: B) -> AndThenFactory<A, B>
pub fn new(svc1: A, svc2: B) -> AndThenFactory<A, B>
Combines two factories without creating their services yet.
ServiceFactory::create creates the children in argument order and
joins them into an AndThen service.
§Example
use ntex_service::{ServiceFactory, dev::AndThenFactory, fn_factory, fn_service};
let first = fn_factory(async |offset: &u32| {
let offset = *offset;
Ok::<_, ()>(fn_service(async move |req: u32| Ok::<_, ()>(req + offset)))
});
let second = fn_factory(async |_: &u32| {
Ok::<_, ()>(fn_service(async |value: u32| Ok::<_, ()>(value.to_string())))
});
let pipeline = AndThenFactory::new(first, second).pipeline(10).await?;
assert_eq!(pipeline.call(2).await?, "12");Trait Implementations§
Source§impl<A, B> Clone for AndThenFactory<A, B>
impl<A, B> Clone for AndThenFactory<A, B>
Source§fn clone(&self) -> AndThenFactory<A, B>
fn clone(&self) -> AndThenFactory<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 AndThenFactory<A, B>
impl<A, B> Debug for AndThenFactory<A, B>
Source§impl<A, B, St, Req> ServiceFactory<St, Req> for AndThenFactory<A, B>where
A: ServiceFactory<St, Req>,
B: ServiceFactory<St, <A as ServiceFactory<St, Req>>::Res, Error = <A as ServiceFactory<St, Req>>::Error, InitError = <A as ServiceFactory<St, Req>>::InitError>,
impl<A, B, St, Req> ServiceFactory<St, Req> for AndThenFactory<A, B>where
A: ServiceFactory<St, Req>,
B: ServiceFactory<St, <A as ServiceFactory<St, Req>>::Res, Error = <A as ServiceFactory<St, Req>>::Error, InitError = <A as ServiceFactory<St, Req>>::InitError>,
Source§type Res = <B as ServiceFactory<St, <A as ServiceFactory<St, Req>>::Res>>::Res
type Res = <B as ServiceFactory<St, <A as ServiceFactory<St, Req>>::Res>>::Res
Source§type Error = <A as ServiceFactory<St, Req>>::Error
type Error = <A as ServiceFactory<St, Req>>::Error
Source§type Service = AndThen<<A as ServiceFactory<St, Req>>::Service, <B as ServiceFactory<St, <A as ServiceFactory<St, Req>>::Res>>::Service>
type Service = AndThen<<A as ServiceFactory<St, Req>>::Service, <B as ServiceFactory<St, <A as ServiceFactory<St, Req>>::Res>>::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<<AndThenFactory<A, B> as ServiceFactory<St, Req>>::Service, <AndThenFactory<A, B> as ServiceFactory<St, Req>>::InitError>
async fn create( &self, st: &St, ) -> Result<<AndThenFactory<A, B> as ServiceFactory<St, Req>>::Service, <AndThenFactory<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.