sm_macro

Crates.iosm_macro
lib.rssm_macro
version0.9.0
sourcesrc
created_at2018-09-18 17:06:34.983638
updated_at2019-11-09 16:37:01.145842
description💋 SM – a static State Machine macro
homepage
repositoryhttps://github.com/rustic-games/sm
max_upload_size
id85381
size62,992
Jean Mertz (JeanMertz)

documentation

README

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);
}
Commit count: 157

cargo fmt