StateMachine

Trait StateMachine 

Source
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§

Source

type InitialState

The initial state of the state machine.

Source

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.

Source

type StatesEnum

The generator enum containing all states

Required Methods§

Source

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.

Source

fn step(&mut self) -> Result<(), Self::Error>

The step function that executes all states and transitions.

Source

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.

Source

fn peek_state(&self) -> &Self::StatesEnum

Peek the internal states enum.

Implementors§