#[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;
const USER_KEY: &str = "user_data";
#[derive(Deserialize, Clone)]
struct User {
id: u64,
name: String,
}
#[attribute(USER_KEY => user: User)]
async fn handle_with_attribute(ctx: Context) {
if let Some(user_data) = user {
// Use the extracted attribute
}
}
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.