Finite state machines in rust; bendns fork to add types.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use rust_fsm::*;

state_machine! {
    #[derive(Debug)]
    #[repr(C)]
    Door => Action => __

    Open => Key => Closed,
    Closed => Key => Open,
    Open => Break => Broken,
    Closed => Break => Broken,
}

#[test]
fn simple() {
    let mut machine = Door::Open;
    machine.consume(Action::Key).unwrap();
    println!("{machine:?}");
    machine.consume(Action::Key).unwrap();
    println!("{machine:?}");
    machine.consume(Action::Break).unwrap();
    println!("{machine:?}");
}