Skip to main content

allframe_handler

Attribute Macro allframe_handler 

Source
#[allframe_handler]
Expand description

Mark a function as an AllFrame router handler.

This attribute suppresses dead_code warnings that occur because the Rust compiler cannot trace function usage through router.register("name", handler_fn) closure chains. It also validates the handler signature at compile time.

§Basic handler

#[allframe_handler]
async fn get_user() -> String {
    r#"{"name":"Alice"}"#.to_string()
}

router.register("get_user", get_user);

§Streaming handler

use allframe_core::router::StreamSender;

#[allframe_handler(streaming)]
async fn stream_data(tx: StreamSender) -> String {
    tx.send("chunk".to_string()).await.ok();
    "done".to_string()
}

router.register_streaming("stream_data", stream_data);

§Validation

  • Function must be async
  • streaming handlers must have a StreamSender parameter
  • Non-streaming handlers must not have a StreamSender parameter