Skip to main content

StateMachine

Trait StateMachine 

Source
pub trait StateMachine {
    type State: Clone + PartialEq + Debug;
    type Event: Clone + Debug;

    // Required methods
    fn state(&self) -> &Self::State;
    fn transition(&mut self, event: &Self::Event) -> &Self::State;
    fn can_transition(&self, event: &Self::Event) -> bool;
}
Expand description

Generic state machine trait. S = state type (typically an enum), E = event type (typically an enum).

Required Associated Types§

Required Methods§

Source

fn state(&self) -> &Self::State

Current state

Source

fn transition(&mut self, event: &Self::Event) -> &Self::State

Process an event, potentially transitioning to a new state. Returns the new state (or current if no transition).

Source

fn can_transition(&self, event: &Self::Event) -> bool

Check if a transition is valid without executing it

Implementors§