Skip to main content

Handler

Trait Handler 

Source
pub trait Handler: Send + Sync {
    // Required method
    fn handle(&self, req: &Request) -> Response;
}
Expand description

Turns a Request into a Response.

The trait is deliberately synchronous: the engine is sans-I/O and every runtime (thread pool, tokio, mio) calls the handler the same way, so a single handler implementation works everywhere. Handlers must be Send + Sync because they are shared across worker threads / tasks.

Required Methods§

Source

fn handle(&self, req: &Request) -> Response

Handle one request and produce the response to send back.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl Handler for Router

Source§

impl Handler for StaticFiles

Source§

impl<F> Handler for F
where F: Fn(&Request) -> Response + Send + Sync,

Any Fn(&Request) -> Response is a handler.