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

#16 in Simulation

Download history 13/week @ 2019-10-04 12/week @ 2019-10-11 27/week @ 2019-10-18 32/week @ 2019-10-25 5/week @ 2019-11-01 25/week @ 2019-11-08 36/week @ 2019-11-15 42/week @ 2019-11-22 38/week @ 2019-11-29 43/week @ 2019-12-06 29/week @ 2019-12-13 3/week @ 2019-12-20 11/week @ 2019-12-27 28/week @ 2020-01-03 24/week @ 2020-01-10

103 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