rs_state_machine

Crates.iors_state_machine
lib.rsrs_state_machine
version2.0.0
sourcesrc
created_at2022-03-31 20:42:17.72969
updated_at2022-05-05 20:50:31.856357
descriptionA business-oriented state machine library
homepage
repositoryhttps://github.com/AdrienHallet/rs_state_machine
max_upload_size
id559881
size25,682
(AdrienHallet)

documentation

https://docs.rs/rs_state_machine

README

Rust State Machine

Build

A (Finite) State Machine library

This Rust Library aims to provide a developer-friendly, Business-Oriented, (Finite) State Machine.

Features

  • Use any type for your States and Events
  • Define State Machines, even easier with the library's DSL
  • Apply events on states to know the output
  • Guard functions on transitions

More features coming Soon™

Examples

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 States and Events, 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);
}
Commit count: 59

cargo fmt