logo

Attribute Macro salvo_core::fn_handler

source · []
#[fn_handler]
Expand description

fn_handler is a pro macro to help create Handler from function easily.

Handler is a trait, fn_handler will convert you fn to a struct, and then implement Handler.

#[async_trait]
pub trait Handler: Send + Sync + 'static {
    async fn handle(&self, req: &mut Request, depot: &mut Depot, res: &mut Response, ctrl: &mut FlowCtrl);
}

After use fn_handler, you don’t need to care arguments’ order, omit unused arguments:

#[fn_handler]
async fn hello_world() -> &'static str {
    "Hello World"
}