Skip to main content

Stack

Struct Stack 

Source
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§

Source§

impl<Inner, Outer> Stack<Inner, Outer>

Source

pub fn new(inner: Inner, outer: Outer) -> Self

Stores two middleware values in inner-to-outer construction order.

No service is created until Middleware::create is called. The resulting outer wrapper receives requests before the inner wrapper.

Trait Implementations§

Source§

impl<Inner: Clone, Outer: Clone> Clone for Stack<Inner, Outer>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Inner: Debug, Outer: Debug> Debug for Stack<Inner, Outer>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S, St, Inner, Outer> Middleware<S, St> for Stack<Inner, Outer>
where Inner: Middleware<S, St>, Outer: Middleware<Inner::Service, St>,

Source§

type Service = <Outer as Middleware<<Inner as Middleware<S, St>>::Service, St>>::Service

Wrapper returned by Self::create. Read more
Source§

fn create(&self, st: &St, service: S) -> Self::Service

Wraps service using the supplied construction state. Read more
Source§

fn apply_to<Sf, Req>( self, factory: Sf, ) -> ServiceChainFactory<ApplyMiddleware<Self, Sf>, St, Req>
where Sf: ServiceFactory<St, Req, Service = S>, Self: Sized, Self::Service: Service<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>
where Inner: Freeze, Outer: Freeze,

§

impl<Inner, Outer> RefUnwindSafe for Stack<Inner, Outer>
where Inner: RefUnwindSafe, Outer: RefUnwindSafe,

§

impl<Inner, Outer> Send for Stack<Inner, Outer>
where Inner: Send, Outer: Send,

§

impl<Inner, Outer> Sync for Stack<Inner, Outer>
where Inner: Sync, Outer: Sync,

§

impl<Inner, Outer> Unpin for Stack<Inner, Outer>
where Inner: Unpin, Outer: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.