#[attribute]Expand description
Extracts a specific attribute value into a variable.
This attribute macro retrieves a specific attribute by key and makes it available as a typed variable from the request context.
ยงUsage
use hyperlane::*;
use hyperlane_macros::*;
use serde::{Deserialize, Serialize};
const TEST_ATTRIBUTE_KEY: &str = "test_attribute_key";
#[derive(Debug, Serialize, Deserialize, Clone)]
struct TestData {
name: String,
age: u32,
}
#[route("/attribute")]
struct Attribute;
impl ServerHook for Attribute {
async fn new(_ctx: &Context) -> Self {
Self
}
#[response_body(&format!("request attribute: {request_attribute_option:?}"))]
#[attribute(TEST_ATTRIBUTE_KEY => request_attribute_option: TestData)]
async fn handle(self, ctx: &Context) {}
}The macro accepts a key-to-variable mapping in the format key => variable_name: Type.
The variable will be available as an Option<Type> in the function scope.