Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Latest commit

Β 

History

History
55 lines (41 loc) Β· 1.24 KB

crates-io.md

File metadata and controls

55 lines (41 loc) Β· 1.24 KB

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);
}