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§
Sourcefn transition(&mut self, event: &Self::Event) -> &Self::State
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).
Sourcefn can_transition(&self, event: &Self::Event) -> bool
fn can_transition(&self, event: &Self::Event) -> bool
Check if a transition is valid without executing it