#state-machine #state #fsm

macro no-std sm_macro

💋 SM – a static State Machine macro

3 releases (breaking)

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

#36 in #fsm

Download history 11543/week @ 2024-03-31 11975/week @ 2024-04-07 11873/week @ 2024-04-14 13950/week @ 2024-04-21 12613/week @ 2024-04-28 13964/week @ 2024-05-05 14418/week @ 2024-05-12 14614/week @ 2024-05-19 16943/week @ 2024-05-26 16713/week @ 2024-06-02 15303/week @ 2024-06-09 20551/week @ 2024-06-16 15629/week @ 2024-06-23 15221/week @ 2024-06-30 15924/week @ 2024-07-07 12658/week @ 2024-07-14

60,057 downloads per month
Used in sm

MIT/Apache

53KB
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

~2MB
~46K SLoC