Trait rustfsm_trait::StateMachine [−][src]
pub trait StateMachine: Sized { type Error: Error; type State; type SharedState; type Event; type Command; fn on_event(self, event: Self::Event) -> TransitionResult<Self, Self::State>; fn name(&self) -> &str; fn state(&self) -> &Self::State; fn set_state(&mut self, new_state: Self::State); fn shared_state(&self) -> &Self::SharedState; fn on_final_state(&self) -> bool; fn from_parts(shared: Self::SharedState, state: Self::State) -> Self; fn visualizer() -> &'static str; fn on_event_mut(
&mut self,
event: Self::Event
) -> Result<Vec<Self::Command>, MachineError<Self::Error>>
where
Self: Clone, { ... } }
This trait defines a state machine (more formally, a finite state transducer) which accepts events (the input alphabet), uses them to mutate itself, and (may) output some commands (the output alphabet) as a result.
Associated Types
type Error: Error
[src]
The error type produced by this state machine when handling events
type State
[src]
The type used to represent different machine states. Should be an enum.
type SharedState
[src]
The type used to represent state that common among all states. Should be a struct.
type Event
[src]
The type used to represent events the machine handles. Should be an enum.
type Command
[src]
The type used to represent commands the machine issues upon transitions.
Required methods
fn on_event(self, event: Self::Event) -> TransitionResult<Self, Self::State>
[src]
Handle an incoming event, returning a transition result which represents updates to apply to the state machine.
fn name(&self) -> &str
[src]
fn state(&self) -> &Self::State
[src]
Returns the current state of the machine
fn set_state(&mut self, new_state: Self::State)
[src]
fn shared_state(&self) -> &Self::SharedState
[src]
Returns the current shared state of the machine
fn on_final_state(&self) -> bool
[src]
Returns true if the machine’s current state is a final one
fn from_parts(shared: Self::SharedState, state: Self::State) -> Self
[src]
Given the shared data and new state, create a new instance.
fn visualizer() -> &'static str
[src]
Return a PlantUML definition of the fsm that can be used to visualize it
Provided methods
fn on_event_mut(
&mut self,
event: Self::Event
) -> Result<Vec<Self::Command>, MachineError<Self::Error>> where
Self: Clone,
[src]
&mut self,
event: Self::Event
) -> Result<Vec<Self::Command>, MachineError<Self::Error>> where
Self: Clone,
Handle an incoming event and mutate the state machine to update to the new state and apply any changes to shared state.
Returns the commands issued by the transition on success, otherwise a MachineError