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

#14 in #finite-state-machine

Download history 10010/week @ 2022-12-06 9454/week @ 2022-12-13 7919/week @ 2022-12-20 7144/week @ 2022-12-27 10420/week @ 2023-01-03 9040/week @ 2023-01-10 9898/week @ 2023-01-17 9045/week @ 2023-01-24 7976/week @ 2023-01-31 7888/week @ 2023-02-07 6728/week @ 2023-02-14 6944/week @ 2023-02-21 6101/week @ 2023-02-28 7608/week @ 2023-03-07 7786/week @ 2023-03-14 8244/week @ 2023-03-21

31,274 downloads per month
Used in 2 crates (via appinsights)

MIT/Apache

23KB
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–255KB