Skip to main content

Crate calimero_sdk_macros

Crate calimero_sdk_macros 

Source
Expand description

Procedural macros for Calimero SDK applications.

This module provides the core procedural macros that enable Calimero applications to define their state, logic, events, and private data structures with minimal boilerplate.

§Key Macros

  • #[app::state] - Defines the application’s persistent state structure
  • #[app::logic] - Defines the application’s business logic implementation
  • #[app::event] - Defines application events for external communication
  • #[app::private] - Defines private data structures for internal use
  • app::emit! - Emits events with optional callback handlers

§Basic Usage

The macros work together to define application state, logic, and events:

  • Use #[app::state] to define persistent application state
  • Use #[app::logic] to implement business logic methods
  • Use #[app::event] to define events for external communication

§Event Emission with Handlers

Use app::emit! macro to emit events:

  • Simple emission: app::emit!(MyEvent::DataChanged { data: "hello" })
  • With callback handler: app::emit!((MyEvent::CounterUpdated { value: 42 }, "counter_handler"))

Macros§

bail
Returns early with an error result.
emit
Emits an event with optional callback handler support.
err
Creates an error result with the given message.
log
Logs a message to the runtime’s logging system.

Attribute Macros§

destroy
Marks a function as the application cleanup function.
event
Defines application events for external communication.
init
Marks a function as the application initialization function.
logic
Defines the application’s business logic implementation.
migrate
Transforms a migration function into a WASM-compatible export.
private
Defines private data structures for internal application use.
state
Defines the application’s persistent state structure.