Function tsukuyomi::handler::wrap_async[][src]

pub fn wrap_async<R>(
    f: impl Fn(&mut Input) -> R
) -> impl Handler where
    R: AsyncResponder

Create an instance of Handler from the provided function.

The provided handler is asynchronous, which means that the handler will process some tasks by using the provided reference to Input and return a future for processing the remaining task.

Examples

fn handler(input: &mut Input) -> impl AsyncResponder<Output = String> {
    input.body_mut().read_all().convert_to()
}

let app = App::builder()
    .route(("/posts", wrap_async(handler)))
    .finish()?;
This example is not tested
#[async]
fn handler() -> tsukuyomi::Result<impl Responder> {
    Ok("Hello")
}

let app = App::builder()
    .route(("/posts", wrap_async(handler)))
    .finish()?;