make_handler

Function make_handler 

Source
pub fn make_handler<F, RespBody, Err, Ret>(f: F) -> HandlerFn<F>
where RespBody: Body, Err: Into<Box<dyn Error + Send + Sync>>, Ret: Future<Output = Result<Response<RespBody>, Err>>, F: Fn(Request<ReqBody>) -> Ret,
Expand description

Creates a new handler from an async function

This function wraps an async function in a HandlerFn type that implements the Handler trait.

§Arguments

§Examples

use micro_http::handler::make_handler;
use http::{Request, Response};
use micro_http::protocol::body::ReqBody;
use std::error::Error;

async fn my_handler(req: Request<ReqBody>) -> Result<Response<String>, Box<dyn Error + Send + Sync>> {
    Ok(Response::new("Hello".to_string()))
}

let handler = make_handler(my_handler);