Expand description
§YASM (Yet Another State Machine)
A modern, efficient deterministic state machine library designed for Rust 2024 edition.
§Features
- Deterministic State Machine: Each state+input combination has at most one possible next state
- Type Safety: Leverage Rust’s type system to ensure state machine correctness
- Macro Support: Use declarative macros to quickly define state machines
- History Tracking: Automatically maintain state transition history for debugging and analysis
- Query Functions: Rich state machine analysis capabilities
- Documentation Generation: Automatically generate Mermaid diagrams and transition tables
- Serde Support: Optional serialization and deserialization support
§Basic Usage
use yasm::*;
// Define state machine
define_state_machine! {
name: TrafficLight,
states: { Red, Yellow, Green },
inputs: { Timer, Emergency },
initial: Red,
transitions: {
Red + Timer => Green,
Green + Timer => Yellow,
Yellow + Timer => Red,
Red + Emergency => Yellow,
Green + Emergency => Red,
Yellow + Emergency => Red
}
}
// Create state machine instance
let mut traffic_light = StateMachineInstance::<TrafficLight>::new();
// Execute state transition
traffic_light.transition(Input::Timer).unwrap();
assert_eq!(*traffic_light.current_state(), State::Green);
§Module Structure
Re-exports§
pub use callbacks::CallbackRegistry;
pub use core::StateMachine;
pub use doc::StateMachineDoc;
pub use instance::StateMachineInstance;
pub use query::StateMachineQuery;
Modules§
Macros§
- define_
state_ machine - Macro for defining deterministic state machines - non-serde version
Constants§
- DEFAULT_
MAX_ HISTORY_ SIZE - Default maximum history size