Trait Handler

Source
pub trait Handler: Send + Sync {
    type RespBody: Body;
    type Error: Into<Box<dyn Error + Send + Sync>>;
    type Fut<'fut>: Future<Output = Result<Response<Self::RespBody>, Self::Error>>
       where Self: 'fut;

    // Required method
    fn call(&self, req: Request<ReqBody>) -> Self::Fut<'_>;
}
Expand description

A trait for handling HTTP requests

This trait defines the core interface for processing HTTP requests and generating responses. Implementors of this trait can be used to handle requests in the HTTP server.

§Type Parameters

  • RespBody: The response body type that implements Body
  • Error: The error type that can be converted into a boxed error
  • Fut: The future type returned by the handler

Required Associated Types§

Source

type RespBody: Body

The type of the response body

Source

type Error: Into<Box<dyn Error + Send + Sync>>

The error type returned by the handler

Source

type Fut<'fut>: Future<Output = Result<Response<Self::RespBody>, Self::Error>> where Self: 'fut

The future type returned by the handler

Required Methods§

Source

fn call(&self, req: Request<ReqBody>) -> Self::Fut<'_>

Process an HTTP request and return a future that resolves to a response

§Arguments
  • req - The HTTP Request to process

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§

Source§

impl<RespBody, Err, F, Fut> Handler for HandlerFn<F>
where RespBody: Body, F: Fn(Request<ReqBody>) -> Fut + Send + Sync, Err: Into<Box<dyn Error + Send + Sync>>, Fut: Future<Output = Result<Response<RespBody>, Err>> + Send,

Source§

type RespBody = RespBody

Source§

type Error = Err

Source§

type Fut<'fut> = Fut where Self: 'fut