pub trait Middleware<Item, Input, Output, Error> {
// Required methods
fn before(&mut self, item: &Item, input: &Input) -> Result<(), Error>;
fn after(
&mut self,
item: &Item,
input: &Input,
output: &mut Output,
) -> Result<(), Error>;
}Expand description
Runs logic immediately before and after the selected handler.
The input is immutable because item selection has already happened. This prevents middleware from invalidating the match. The output remains mutable so middleware can decorate or normalize successful results.
Required Methods§
Sourcefn before(&mut self, item: &Item, input: &Input) -> Result<(), Error>
fn before(&mut self, item: &Item, input: &Input) -> Result<(), Error>
Runs after an item is selected and before its handler is called.
Sourcefn after(
&mut self,
item: &Item,
input: &Input,
output: &mut Output,
) -> Result<(), Error>
fn after( &mut self, item: &Item, input: &Input, output: &mut Output, ) -> Result<(), Error>
Runs after the handler succeeds.
This hook is skipped when Self::before or Handler::handle fails.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".