Macro sfsm_proc::add_state_machine
source · [−]add_state_machine!() { /* proc-macro */ }
Expand description
Generates a state machine from a given state machine definition.
The state machine definition is expected too hold to the following pattern:
ⓘ
add_state_machine!(
StateMachineName,
InitialState,
[State1, State2, StateN, ...],
[StateN => StateN, ...]
);
- StateMachineName: Defines the name of the state machine.
- InitialState: The initial state the state machine will start with.
- [State1, State2, StateN, …]: Specifies all state structs that will be known to the state machine. Each state must implement the
State
trait. - [StateN => StateN, …]: Defines all transitions between states that can occur. For each transition, the state must implement the according
Transition
trait.
An example might look like this:
add_state_machine!(
#[derive(Debug)]
Rocket,
Action<Ascent>,
[Action<Ascent>, Action<Descent>],
[
Action<Ascent> => Action<Descent>,
Action<Descent> => Action<Ascent>
]
);
Expand the example to see more, or check out the examples folder for a more complete example.