pub struct Stack<Inner, Outer> { /* private fields */ }Expand description
Two middleware values applied in sequence.
Construction applies inner first, then outer, with the same state
reference: the result is outer(inner(service)). Requests enter the outer
wrapper first; if forwarded, they then pass through the inner wrapper to
the service. Responses return through the inner wrapper before the outer.
The stack only composes construction. Lifecycle forwarding and whether calls reach the inner service are determined by each wrapper. Cloning clones both middleware values without constructing a service.
§Example
use ntex_service::{Middleware, Service, Stack, fn_layer, fn_service};
let inner = fn_layer(async |req: u32, ctx| ctx.call(req + 1).await);
let outer = fn_layer(async |req: u32, ctx| ctx.call(req * 2).await);
let service = Stack::new(inner, outer)
.create(&(), fn_service(async |req: u32| Ok::<_, ()>(req)));
let pipeline = service.pipeline(());
assert_eq!(pipeline.call(2).await?, 5);Implementations§
Trait Implementations§
Source§impl<S, St, Inner, Outer> Middleware<S, St> for Stack<Inner, Outer>
impl<S, St, Inner, Outer> Middleware<S, St> for Stack<Inner, Outer>
Source§type Service = <Outer as Middleware<<Inner as Middleware<S, St>>::Service, St>>::Service
type Service = <Outer as Middleware<<Inner as Middleware<S, St>>::Service, St>>::Service
Wrapper returned by
Self::create. Read moreSource§fn create(&self, st: &St, service: S) -> Self::Service
fn create(&self, st: &St, service: S) -> Self::Service
Wraps
service using the supplied construction state. Read moreSource§fn apply_to<Sf, Req>(
self,
factory: Sf,
) -> ServiceChainFactory<ApplyMiddleware<Self, Sf>, St, Req>
fn apply_to<Sf, Req>( self, factory: Sf, ) -> ServiceChainFactory<ApplyMiddleware<Self, Sf>, St, Req>
Creates a service factory that instantiates a service and applies
the current middleware to it. Read more
Auto Trait Implementations§
impl<Inner, Outer> Freeze for Stack<Inner, Outer>
impl<Inner, Outer> RefUnwindSafe for Stack<Inner, Outer>where
Inner: RefUnwindSafe,
Outer: RefUnwindSafe,
impl<Inner, Outer> Send for Stack<Inner, Outer>
impl<Inner, Outer> Sync for Stack<Inner, Outer>
impl<Inner, Outer> Unpin for Stack<Inner, Outer>
impl<Inner, Outer> UnsafeUnpin for Stack<Inner, Outer>where
Inner: UnsafeUnpin,
Outer: UnsafeUnpin,
impl<Inner, Outer> UnwindSafe for Stack<Inner, Outer>where
Inner: UnwindSafe,
Outer: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more