Skip to main content

function

Attribute Macro function 

Source
#[function]
Expand description

Re-export the proc macro. Attribute macro for registering durable functions.

Detects the function kind from the first parameter’s type:

  • &Context → Workflow
  • &Info → Leaf with metadata
  • anything else → Pure leaf

Generates a PascalCase unit struct implementing Durable, plus a lowercase const alias matching the original function name. The original function is consumed — its body is inlined into the Durable::execute impl.

§Examples

#[resonate_sdk::function]
async fn my_leaf(x: i32) -> Result<i32> { Ok(x + 1) }

#[resonate_sdk::function]
async fn my_workflow(ctx: &Context, x: i32) -> Result<i32> {
    ctx.run(my_leaf, x).await
}

// Both lowercase const and PascalCase struct work:
ctx.run(my_leaf, 42).await     // preferred
ctx.run(MyLeaf, 42).await      // also works
resonate.register(my_leaf)     // preferred
resonate.register(MyLeaf)      // also works