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, 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

Source§

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

Handler for async functions with no extractors (just returns a response)

Source§

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

Source§

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

Handler for async functions that take Request directly

Source§

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

Source§

impl<F, Fut, Res, E1> Handler<(E1,)> for F
where F: Fn(E1) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = Res> + Send + 'static, Res: IntoResponse, E1: FromRequestParts + Send + 'static,

Handler for functions with one extractor

Source§

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

Source§

impl<F, Fut, Res, E1, E2> Handler<(E1, E2)> for F
where F: Fn(E1, E2) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = Res> + Send + 'static, Res: IntoResponse, E1: FromRequestParts + Send + 'static, E2: FromRequestParts + Send + 'static,

Handler for functions with two extractors

Source§

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

Source§

impl<F, Fut, Res, E1, E2, E3> Handler<(E1, E2, E3)> for F
where F: Fn(E1, E2, E3) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = Res> + Send + 'static, Res: IntoResponse, E1: FromRequestParts + Send + 'static, E2: FromRequestParts + Send + 'static, E3: FromRequestParts + Send + 'static,

Handler for functions with three extractors

Source§

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

Source§

impl<F, Fut, Res, E1, E2, E3, E4> Handler<(E1, E2, E3, E4)> for F
where F: Fn(E1, E2, E3, E4) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = Res> + Send + 'static, Res: IntoResponse, E1: FromRequestParts + Send + 'static, E2: FromRequestParts + Send + 'static, E3: FromRequestParts + Send + 'static, E4: FromRequestParts + Send + 'static,

Handler for functions with four extractors

Source§

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