Trait gotham::middleware::NewMiddleware
source · [−]pub trait NewMiddleware: Sync + RefUnwindSafe {
type Instance: Middleware;
fn new_middleware(&self) -> Result<Self::Instance>;
}
Expand description
A type which is used to spawn new Middleware
values. When implementing a Middleware
, this
defines how instances of the Middleware
are created.
This can be derived by Middleware
that implement Clone
, and will result in the following
implementation:
struct MyMiddleware;
impl NewMiddleware for MyMiddleware {
type Instance = Self;
fn new_middleware(&self) -> anyhow::Result<Self::Instance> {
Ok(self.clone())
}
}
Required Associated Types
sourcetype Instance: Middleware
type Instance: Middleware
The type of Middleware
created by the NewMiddleware
.
Required Methods
sourcefn new_middleware(&self) -> Result<Self::Instance>
fn new_middleware(&self) -> Result<Self::Instance>
Create and return a new Middleware
value.
Implementors
sourceimpl NewMiddleware for CookieParser
impl NewMiddleware for CookieParser
NewMiddleware
trait implementation.
type Instance = CookieParser
sourceimpl NewMiddleware for RequestLogger
impl NewMiddleware for RequestLogger
Implementation of NewMiddleware
is required for Gotham middleware.
This will simply dereference the internal state, rather than deriving NewMiddleware
which will clone the structure - should be cheaper for repeated calls.
type Instance = RequestLogger
sourceimpl NewMiddleware for SimpleLogger
impl NewMiddleware for SimpleLogger
Implementation of NewMiddleware
is required for Gotham middleware.
This will simply dereference the internal state, rather than deriving NewMiddleware
which will clone the structure - should be cheaper for repeated calls.
type Instance = SimpleLogger
sourceimpl NewMiddleware for SecurityMiddleware
impl NewMiddleware for SecurityMiddleware
NewMiddleware
trait implementation.
type Instance = SecurityMiddleware
sourceimpl NewMiddleware for RequestTimer
impl NewMiddleware for RequestTimer
NewMiddleware
trait implementation.
type Instance = RequestTimer
sourceimpl<T> NewMiddleware for StateMiddleware<T>where
T: Clone + RefUnwindSafe + StateData + Sync,
impl<T> NewMiddleware for StateMiddleware<T>where
T: Clone + RefUnwindSafe + StateData + Sync,
NewMiddleware
trait implementation.