Crates.io | rs_state_machine |
lib.rs | rs_state_machine |
version | 2.0.0 |
source | src |
created_at | 2022-03-31 20:42:17.72969 |
updated_at | 2022-05-05 20:50:31.856357 |
description | A business-oriented state machine library |
homepage | |
repository | https://github.com/AdrienHallet/rs_state_machine |
max_upload_size | |
id | 559881 |
size | 25,682 |
A (Finite) State Machine library
This Rust Library aims to provide a developer-friendly, Business-Oriented, (Finite) State Machine.
More features coming Soon™
Quickly define your State Machine using the integrated DSL define!()
macro:
fn main() {
let light_switch = define!(
"OFF" - "TURN_ON" -> "ON",
"ON" - "TURN_OFF" -> "OFF"
);
}
Use any type to define your State
s and Event
s, why not enums:
fn main() {
let mut enum_light_switch = Machine::new();
enum_light_switch.add_transition(Transition::new(LightState::Off, LightEvent::TurnOn, LightState::On));
enum_light_switch.add_transition(Transition::new(LightState::On, LightEvent::TurnOff, LightState::Off));
let mut state_light = StatefulLight { state: LightState::Off };
enum_light_switch.apply(&mut state_light, LightEvent::TurnOn);
}