#state-machine #fsm #state

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 15667/week @ 2024-07-20 12249/week @ 2024-07-27 16119/week @ 2024-08-03 14130/week @ 2024-08-10 14445/week @ 2024-08-17 14998/week @ 2024-08-24 11270/week @ 2024-08-31 11542/week @ 2024-09-07 12471/week @ 2024-09-14 7347/week @ 2024-09-21 6119/week @ 2024-09-28 4196/week @ 2024-10-05 3112/week @ 2024-10-12 4740/week @ 2024-10-19 2741/week @ 2024-10-26 2888/week @ 2024-11-02

14,612 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
~48K SLoC