Trait Handler

Source
pub trait Handler<T>:
    Clone
    + Send
    + Sync
    + 'static {
    type Future: Future<Output = Response> + Send + 'static;

    // Required method
    fn call(&self, req: Request) -> Self::Future;
}
Expand description

A trait for handling HTTP requests

Required Associated Types§

Source

type Future: Future<Output = Response> + Send + 'static

The future type returned by the handler

Required Methods§

Source

fn call(&self, req: Request) -> Self::Future

Handle the request and return a response

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<F> Handler<((),)> for F
where F: Fn(Request) -> Response + Clone + Send + Sync + 'static,

Implement Handler for functions that return Response directly (sync handlers)

Source§

type Future = Pin<Box<dyn Future<Output = Response> + Send>>

Source§

impl<F, Fut> Handler<()> for F
where F: Fn(Request) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = Response> + Send + 'static,

Implement Handler for async functions that take Request and return Response

Source§

type Future = Fut