pub trait StateMachine {
type InitialState;
type Error;
type StatesEnum;
// Required methods
fn start(&mut self, state: Self::InitialState) -> Result<(), Self::Error>;
fn step(&mut self) -> Result<(), Self::Error>;
fn stop(self) -> Result<Self::StatesEnum, Self::Error>;
fn peek_state(&self) -> &Self::StatesEnum;
}
Expand description
Trait that will be implemented for the state machine.
Required Associated Types§
Sourcetype InitialState
type InitialState
The initial state of the state machine.
Sourcetype Error
type Error
The returned error. This is also implemented in non fallible state machines, but will be ignore as there is no case this error could occur.
Sourcetype StatesEnum
type StatesEnum
The generator enum containing all states
Required Methods§
Sourcefn start(&mut self, state: Self::InitialState) -> Result<(), Self::Error>
fn start(&mut self, state: Self::InitialState) -> Result<(), Self::Error>
Start function that must be called first. It populates the internal enum with the initial state. If step is called before start, the state machine will return an error.
Sourcefn step(&mut self) -> Result<(), Self::Error>
fn step(&mut self) -> Result<(), Self::Error>
The step function that executes all states and transitions.
Sourcefn stop(self) -> Result<Self::StatesEnum, Self::Error>
fn stop(self) -> Result<Self::StatesEnum, Self::Error>
If desired, the state machine can be stopped. When doing so, the internal states enum is returned.
Sourcefn peek_state(&self) -> &Self::StatesEnum
fn peek_state(&self) -> &Self::StatesEnum
Peek the internal states enum.