Skip to main content

AddMiddlewareExt

Trait AddMiddlewareExt 

Source
pub trait AddMiddlewareExt {
    // Required methods
    fn add_middleware<T>(&self, middleware: impl Into<Arc<T>>)
       where T: Middleware + 'static;
    fn has_middleware<T>(&self) -> bool
       where T: Middleware + 'static;
}
Expand description

Registers concrete Middleware instances so the router macros can resolve them.

Lives on AppContext, so middleware can be registered while configuring the AppBuilder or from within a plugin’s build. A middleware is identified by its type and stored as an Arc<T> component; reference it from a router with the #[router(middleware = [..])] / #[route(middleware = [..])] attributes.

Required Methods§

Source

fn add_middleware<T>(&self, middleware: impl Into<Arc<T>>)
where T: Middleware + 'static,

Registers middleware so routers can reference it by type T.

§Panics

Panics if a middleware of type T is already registered (as an instance, or - once the app is built - as a service). Guard with has_middleware when this can happen.

Source

fn has_middleware<T>(&self) -> bool
where T: Middleware + 'static,

Returns whether a middleware of type T is registered (its Arc<T> is present as a component).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl AddMiddlewareExt for AppContext

Source§

fn add_middleware<T>(&self, middleware: impl Into<Arc<T>>)
where T: Middleware + 'static,

Source§

fn has_middleware<T>(&self) -> bool
where T: Middleware + 'static,

Implementors§