Macro define_state_machine

Source
macro_rules! define_state_machine {
    (
        name: $name:ident,
        states: { $($state:ident),* $(,)? },
        inputs: { $($input:ident),* $(,)? },
        initial: $initial:ident,
        transitions: {
            $(
                $from:ident + $inp:ident => $to:ident
            ),* $(,)?
        }
    ) => { ... };
}
Expand description

Macro for defining deterministic state machines - non-serde version

This macro is used to quickly define deterministic state machines where each state+input combination can have at most one next state.

§Syntax

use yasm::define_state_machine;
define_state_machine! {
    name: MyStateMachine,
    states: { State1, State2, State3 },
    inputs: { Input1, Input2 },
    initial: State1,
    transitions: {
        State1 + Input1 => State2,
        State2 + Input2 => State3,
    }
}

§Parameters

  • name: Name of the state machine struct
  • states: List of all possible states
  • inputs: List of all possible inputs
  • initial: Initial state
  • transitions: State transition rules in the format from_state + input => to_state