Skip to main content

Handler

Trait Handler 

Source
pub trait Handler: Send + Sync {
    // Required method
    fn call<'a>(
        &'a self,
        ctx: &'a RequestContext,
        req: &'a mut Request,
    ) -> BoxFuture<'a, Response>;

    // Provided method
    fn dependency_overrides(&self) -> Option<Arc<DependencyOverrides>> { ... }
}
Expand description

A handler that processes requests into responses.

This trait abstracts over handler functions, allowing middleware to wrap any type that can handle requests.

Required Methods§

Source

fn call<'a>( &'a self, ctx: &'a RequestContext, req: &'a mut Request, ) -> BoxFuture<'a, Response>

Process a request and return a response.

Provided Methods§

Source

fn dependency_overrides(&self) -> Option<Arc<DependencyOverrides>>

Optional dependency overrides to apply when building request contexts.

Default implementation returns None, which means no overrides.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<H: Handler + ?Sized> Handler for Arc<H>

Delegate Handler to an Arc-wrapped handler.

This is a convenience for building apps behind Arc (common in tests and when cloning shared handlers).

Source§

fn call<'a>( &'a self, ctx: &'a RequestContext, req: &'a mut Request, ) -> BoxFuture<'a, Response>

Source§

fn dependency_overrides(&self) -> Option<Arc<DependencyOverrides>>

Implementors§

Source§

impl Handler for App

Source§

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

Implement Handler for async functions.

This allows any async function with the signature async fn(&RequestContext, &mut Request) -> Response to be used as a handler.

Source§

impl<M: Middleware, H: Handler> Handler for Layered<M, H>