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 8351/week @ 2024-01-13 8670/week @ 2024-01-20 8179/week @ 2024-01-27 6428/week @ 2024-02-03 9118/week @ 2024-02-10 9095/week @ 2024-02-17 12391/week @ 2024-02-24 13446/week @ 2024-03-02 10721/week @ 2024-03-09 12903/week @ 2024-03-16 10368/week @ 2024-03-23 11222/week @ 2024-03-30 12287/week @ 2024-04-06 11865/week @ 2024-04-13 13918/week @ 2024-04-20 10078/week @ 2024-04-27

51,102 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