Skip to main content

handler

Attribute Macro handler 

Source
#[handler]
Expand description

Adapts an async function into an rs_netty::Handler implementation.

The MVP form expects a user-declared handler type and an async function with one inbound message argument:

struct Echo;

#[handler(Echo)]
async fn echo(req: Request) -> rs_netty::Result<Response> {
    Ok(Response { echoed: req.message })
}

#[handler(PrintResponse, write = Request)]
async fn print_response(res: Response) -> rs_netty::Result<()> {
    println!("{}", res.message);
    Ok(())
}