#state-machine #state #fsm

no-std sm

💋 SM – a static State Machine library

8 releases (breaking)

0.9.0 Nov 9, 2019
0.7.0 Oct 4, 2018
0.6.1 Sep 18, 2018
0.5.0 Sep 11, 2018
0.1.0 Sep 1, 2018

#26 in #fsm

Download history 11650/week @ 2024-04-01 11738/week @ 2024-04-08 11951/week @ 2024-04-15 13947/week @ 2024-04-22 12644/week @ 2024-04-29 13969/week @ 2024-05-06 14429/week @ 2024-05-13 14607/week @ 2024-05-20 16932/week @ 2024-05-27 16701/week @ 2024-06-03 15356/week @ 2024-06-10 20545/week @ 2024-06-17 15638/week @ 2024-06-24 15259/week @ 2024-07-01 15893/week @ 2024-07-08 12962/week @ 2024-07-15

60,310 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

24KB
85 lines

SM aims to be a safe, fast and simple state machine library.

  • safe — Rust's type system, ownership model and exhaustive pattern matching prevent you from mis-using your state machines

  • fast — zero runtime overhead, the machine is 100% static, all validation happens at compile-time

  • simple — five traits, and one optional declarative macro, control-flow only, no business logic attached


You might be looking for:

Quick Example

extern crate sm;
use sm::sm;

sm! {
    Lock {
        InitialStates { Locked }

        TurnKey {
            Locked => Unlocked
            Unlocked => Locked
        }

        Break {
            Locked, Unlocked => Broken
        }
    }
}

fn main() {
    use Lock::*;
    let lock = Machine::new(Locked);
    let lock = lock.transition(TurnKey);

    assert_eq!(lock.state(), Unlocked);
    assert_eq!(lock.trigger().unwrap(), TurnKey);
}

Dependencies

~0–285KB