3 releases (breaking)

✓ Uses Rust 2018 edition

0.9.0 Nov 9, 2019
0.7.0 Oct 4, 2018
0.6.1 Sep 18, 2018

#18 in Simulation

Download history 7/week @ 2019-07-24 9/week @ 2019-07-31 24/week @ 2019-08-07 7/week @ 2019-08-14 16/week @ 2019-08-21 10/week @ 2019-08-28 13/week @ 2019-09-04 12/week @ 2019-09-11 10/week @ 2019-09-18 6/week @ 2019-09-25 5/week @ 2019-10-02 18/week @ 2019-10-09 20/week @ 2019-10-16 31/week @ 2019-10-23 15/week @ 2019-10-30

57 downloads per month
Used in 1 crate

MIT/Apache

52KB
1.5K SLoC

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

~1MB
~27K SLoC