Skip to main content

ServerHook

Trait ServerHook 

Source
pub trait ServerHook:
    Send
    + Sync
    + 'static {
    // Required methods
    fn new(
        stream: &mut Stream,
        ctx: &mut Context,
    ) -> impl Future<Output = Self> + Send;
    fn handle(
        self,
        stream: &mut Stream,
        ctx: &mut Context,
    ) -> impl Future<Output = Status> + 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§

Source

fn new( stream: &mut Stream, ctx: &mut Context, ) -> impl Future<Output = Self> + Send

Creates a new instance of this hook from the context.

This method is called by the framework to instantiate the hook, passing in the Context directly.

§Arguments
  • &mut Stream - The stream object providing server configuration and state
  • &mut Context - The request context containing all request/response data.
§Returns

A future that resolves to a new instance of this hook.

Source

fn handle( self, stream: &mut Stream, ctx: &mut Context, ) -> impl Future<Output = Status> + 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
  • &mut Stream - The stream object providing server configuration and state
  • &mut Context - The request context for accessing request/response data.
§Returns
  • Status - Status::Continue if the pipeline should proceed, Status::Reject if the pipeline should be aborted.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl ServerHook for DefaultServerHook

Implements ServerHook for DefaultServerHook

This implementation provides default no-op handlers for server hook operations.