Skip to main content

Handler

Trait Handler 

Source
pub trait Handler: Send + 'static {
    // Required method
    fn serve(&self, w: &mut ResponseWriter, r: &Request);
}
Expand description

Handler is implemented by any type that can process an inbound NWEP request.

The event loop invokes Handler::serve once per request, on the event loop thread. Closures of type Fn(&mut ResponseWriter, &Request) + Send + 'static implement this trait automatically, so you can pass a closure wherever a Handler is expected.

Required Methods§

Source

fn serve(&self, w: &mut ResponseWriter, r: &Request)

serve processes a single request and writes the response through w.

If serve returns without having called any write method on w, the event loop automatically sends an empty "ok" response so the stream is always closed cleanly.

Implementors§

Source§

impl Handler for Router

Source§

impl<F: Fn(&mut ResponseWriter, &Request) + Send + 'static> Handler for F