epilogue_hooks

Attribute Macro epilogue_hooks 

Source
#[epilogue_hooks]
Expand description

Executes multiple specified functions after the main handler function.

This attribute macro configures multiple post-execution hooks that run after the main function logic. The main function will execute first, followed by the specified hook functions in the order provided.

ยงUsage

use hyperlane::*;
use hyperlane_macros::*;

struct EpilogueHooks;

impl ServerHook for EpilogueHooks {
    async fn new(_ctx: &Context) -> Self {
        Self
    }

    #[response_status_code(200)]
    async fn handle(self, ctx: &Context) {}
}

async fn epilogue_hooks_fn(ctx: Context) {
    let hook = EpilogueHooks::new(&ctx).await;
    hook.handle(&ctx).await;
}

#[route("/hook")]
struct Hook;

impl ServerHook for Hook {
    async fn new(_ctx: &Context) -> Self {
        Self
    }

    #[epilogue_hooks(epilogue_hooks_fn)]
    #[response_body("Testing hook macro")]
    async fn handle(self, ctx: &Context) {}
}

The macro accepts a comma-separated list of function names as parameters. All hook functions and the main function must accept a Context parameter. Avoid combining this macro with other macros on the same function to prevent macro expansion conflicts.