Skip to main content

alien_event

Attribute Macro alien_event 

Source
#[alien_event]
Expand description

A procedural macro that wraps a function with an AlienEvent scope.

This macro is similar to tracing’s #[instrument] but for the Alien events system. It automatically wraps the function body with AlienEvent::in_scope().

§Usage

use alien_macros::alien_event;
use alien_core::{AlienEvent, Result};

#[alien_event(AlienEvent::BuildingStack { stack: "my-stack".to_string() })]
async fn build_stack() -> Result<()> {
    // Function body - all events emitted here will be children
    // of the BuildingStack event
    Ok(())
}

The macro supports any AlienEvent variant:

#[alien_event(AlienEvent::BuildingImage { image: "api:latest".to_string() })]
async fn build_image() -> Result<()> {
    Ok(())
}

You can also use expressions for dynamic values:

#[alien_event(AlienEvent::BuildingStack { stack: format!("stack-{}", id) })]
async fn build_dynamic_stack(id: u32) -> Result<()> {
    Ok(())
}

The macro only works with async functions since it uses AlienEvent::in_scope() internally.