#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

#25 in #fsm

Download history 7283/week @ 2023-12-15 3092/week @ 2023-12-22 5622/week @ 2023-12-29 9812/week @ 2024-01-05 7953/week @ 2024-01-12 8629/week @ 2024-01-19 8278/week @ 2024-01-26 6300/week @ 2024-02-02 8991/week @ 2024-02-09 8772/week @ 2024-02-16 11849/week @ 2024-02-23 13632/week @ 2024-03-01 11377/week @ 2024-03-08 12423/week @ 2024-03-15 11103/week @ 2024-03-22 7946/week @ 2024-03-29

44,713 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–280KB