pub trait ServerHook:
Send
+ Sync
+ 'static {
// Required methods
fn new(ctx: &Context) -> impl Future<Output = Self> + Send;
fn handle(self, ctx: &Context) -> impl Future<Output = ()> + Send;
}Expand description
Trait for server lifecycle hooks that process requests.
ServerHook provides a unified interface for different types of request processing
handlers in the server lifecycle, including route handlers, middleware, and panic hooks.
All hooks follow the same pattern: instantiation via new and execution via handle.
This trait is designed to work with the server’s request processing pipeline, where
each hook receives the Context directly for both initialization and processing.
Required Methods§
Sourcefn handle(self, ctx: &Context) -> impl Future<Output = ()> + Send
fn handle(self, ctx: &Context) -> impl Future<Output = ()> + Send
Executes the hook’s processing logic.
This method contains the actual logic for processing the request.
It receives the Context as a parameter for accessing request/response data.
§Arguments
&Context- The request context for accessing request/response data.
§Returns
A future that resolves when the processing is complete.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.