#fsm #state #state-machine

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

#59 in Simulation

Download history 5814/week @ 2021-09-28 5115/week @ 2021-10-05 4799/week @ 2021-10-12 5460/week @ 2021-10-19 4485/week @ 2021-10-26 3867/week @ 2021-11-02 4310/week @ 2021-11-09 4386/week @ 2021-11-16 1665/week @ 2021-11-23 2284/week @ 2021-11-30 3056/week @ 2021-12-07 3078/week @ 2021-12-14 835/week @ 2021-12-21 1317/week @ 2021-12-28 4020/week @ 2022-01-04 3258/week @ 2022-01-11

9,721 downloads per month
Used in sm

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

~1.5MB
~42K SLoC

-]