Skip to main content

Crate stateless

Crate stateless 

Source
Expand description

A zero-cost state machine macro that separates structure from behavior.

Most state machine libraries couple behavior to the state machine itself — guards, actions, and context structs all get tangled into the DSL. stateless takes the opposite approach: the macro is a pure transition table. It generates two enums and a lookup function. Guards, side effects, and error handling live in your own code, using normal Rust patterns.

§Quick Start

use stateless::statemachine;

statemachine! {
    transitions: {
        *Idle + Start = Running,
        Running + Stop = Idle,
        _ + Reset = Idle,
    }
}

let mut state = State::default(); // Idle (marked with *)
assert_eq!(state, State::Idle);

if let Some(new_state) = state.process_event(Event::Start) {
    state = new_state;
}
assert_eq!(state, State::Running);

See statemachine! for the full DSL reference and all features.

Macros§

statemachine
Generates a state machine from a declarative transition table.