pub struct MiddlewareChain { /* private fields */ }Expand description
Builds and executes the middleware chain
The chain is built from the outside-in:
- Global middleware (first to run)
- Route group middleware
- Route-level middleware
- The actual route handler (innermost)
Implementations§
Source§impl MiddlewareChain
impl MiddlewareChain
Sourcepub fn push(&mut self, middleware: BoxedMiddleware)
pub fn push(&mut self, middleware: BoxedMiddleware)
Add middleware to the chain
Middleware are executed in the order they are added.
Sourcepub fn extend(&mut self, middleware: impl IntoIterator<Item = BoxedMiddleware>)
pub fn extend(&mut self, middleware: impl IntoIterator<Item = BoxedMiddleware>)
Add multiple middleware to the chain
Sourcepub async fn execute(
self,
request: Request,
handler: Arc<BoxedHandler>,
) -> Response
pub async fn execute( self, request: Request, handler: Arc<BoxedHandler>, ) -> Response
Execute the middleware chain with the given request and final handler
The chain is executed from outside-in:
- First middleware added runs first
- Each middleware can call
next(request)to continue the chain - The final handler is called at the end of the chain
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MiddlewareChain
impl !RefUnwindSafe for MiddlewareChain
impl Send for MiddlewareChain
impl Sync for MiddlewareChain
impl Unpin for MiddlewareChain
impl !UnwindSafe for MiddlewareChain
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more