Handler

Trait Handler 

Source
pub trait Handler: Send + Sync {
    // Required method
    fn handle(
        &self,
        req: Request<Body>,
    ) -> Pin<Box<dyn Future<Output = Result<Response<Body>>> + Send + Sync>>;
}
Expand description

Represents a HTTP handler function. This trait is implemented for asynchronous functions that take a Request and return a Result<Response<Body>, hyper::Error>

async fn hello(_: Request<Body>) -> Result<Response<Body>, hyper::Error> {
    Ok(Response::new(Body::empty()))
}

let handler: Box<dyn Handler> = Box::new(hello);

Required Methods§

Source

fn handle( &self, req: Request<Body>, ) -> Pin<Box<dyn Future<Output = Result<Response<Body>>> + Send + Sync>>

Implementors§

Source§

impl<F, R> Handler for F
where F: Fn(Request<Body>) -> R + Send + Sync, R: Future<Output = Result<Response<Body>, Error>> + Send + Sync + 'static,