pub struct MiddlewareStack { /* private fields */ }Expand description
An ordered list of middleware, outermost first.
What a route, a group, or a controller action attaches. The value that replaces a name-keyed group entry.
Implementations§
Source§impl MiddlewareStack
impl MiddlewareStack
Sourcepub fn with(self, middleware: impl Middleware) -> Self
pub fn with(self, middleware: impl Middleware) -> Self
Append a middleware instance.
Sourcepub fn with_arc(self, middleware: Arc<dyn Middleware>) -> Self
pub fn with_arc(self, middleware: Arc<dyn Middleware>) -> Self
Append an already-shared instance.
For middleware built once and attached to several routes — a rate limiter, whose counters are the point of sharing it.
Sourcepub fn with_stack(self, other: MiddlewareStack) -> Self
pub fn with_stack(self, other: MiddlewareStack) -> Self
Append every stage of other, keeping its order.
How a group nests inside a group.
Sourcepub fn deferred<M, F>(self, build: F) -> Self
pub fn deferred<M, F>(self, build: F) -> Self
Append middleware built when the router compiles, from the container.
For anything that cannot exist while routes are being declared: the container is populated by then, and the first request has not arrived. See the module docs.
Sourcepub fn resolved<S, M, F>(self, build: F) -> Self
pub fn resolved<S, M, F>(self, build: F) -> Self
Append middleware built from one service in the container.
The common shape of deferred, with the resolve
spelled once:
MiddlewareStack::new()
.resolved(|auth: Arc<AuthManager<User>>| Authenticate::new(auth))A missing binding fails the boot with the service’s type name in the message, which is the container’s own error.
Sourcepub fn prepend(&mut self, outer: &MiddlewareStack)
pub fn prepend(&mut self, outer: &MiddlewareStack)
Prepend every stage of outer, so it runs first.
How a group’s middleware ends up outside a route’s own.