Procedural macros for the state machines crate.
This crate provides the state_machine! macro for defining
type-safe state machines with transitions, guards, and callbacks.
Architecture
The macro implementation is split into several modules:
- types: Data structures representing state machines
- parser: Parsing macro input into our data structures
- codegen: Generating Rust code from the parsed structures
- validation: Validating state machine definitions
Example
use state_machines::state_machine;
state_machine! {
name: Door,
state: DoorState,
initial: Closed,
states: [Open, Closed],
events: {
open {
transition: { from: Closed, to: Open }
}
close {
transition: { from: Open, to: Closed }
}
}
}