Skip to main content

Handler

Trait Handler 

Source
pub trait Handler<P: Provider>: Sized {
    type Input;
    type Output: Body;
    type Error: Error + Send + Sync;

    // Required methods
    fn from_input(input: Self::Input) -> Result<Self, Self::Error>;
    fn handle(
        self,
        ctx: Context<'_, P>,
    ) -> impl Future<Output = Result<Reply<Self::Output>, Self::Error>> + Send;

    // Provided method
    fn handler(
        input: Self::Input,
    ) -> Result<RequestHandler<RequestSet<Self, P>, NoOwner, NoProvider>, Self::Error> { ... }
}
Expand description

Trait to provide a common interface for request handling.

Required Associated Types§

Source

type Input

The raw input type of the handler.

Source

type Output: Body

The output type of the handler.

Source

type Error: Error + Send + Sync

The error type returned by the handler.

Required Methods§

Source

fn from_input(input: Self::Input) -> Result<Self, Self::Error>

Parse the input into a [Handler] instance.

§Errors

Returns an error if the input cannot be parsed.

Source

fn handle( self, ctx: Context<'_, P>, ) -> impl Future<Output = Result<Reply<Self::Output>, Self::Error>> + Send

Implemented by the request handler to process the request.

Provided Methods§

Source

fn handler( input: Self::Input, ) -> Result<RequestHandler<RequestSet<Self, P>, NoOwner, NoProvider>, Self::Error>

Initialize a [RequestHandler] from raw request.

§Errors

Returns an error if the message cannot be decoded.

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.

Implementors§