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);