pub struct FSM<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType> where
StateType: Clone + Eq + Hash + Sized,
EventType: Clone + Eq + Hash + Sized, {
pub extended_state: RefCell<Box<ExtendedState>>,
/* private fields */
}
Expand description
Finite state machine type
Template parameters
ExtendedState
- provides a structure that every transition can access and stores extended stateTransitionFnArguments
- type that can be boxed as parameters to an event instanceErrorType
- Errors that transitions can generate internally
Fields
extended_state: RefCell<Box<ExtendedState>>
Implementations
implementation of methods to contstruct the machine
new FSM with an initial extended state box’ed up so it can be passed around easily
new FSM copy sharing transitions with this instance. This allows to pull many lightweight
copies of a single FSM template
and run them as independent instances. Observe that any
transition modifications will modify all flyweights.
pub fn add_transition(
&mut self,
from: TransitionSource<StateType, EventType>,
to: TransitionTarget<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>
) -> bool
pub fn add_transition(
&mut self,
from: TransitionSource<StateType, EventType>,
to: TransitionTarget<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>
) -> bool
new transition
returns
- TRUE if transition has been inserted,
FALSE if a previous has been overwritten!
pub fn transitions(
&self
) -> Ref<'_, HashMap<TransitionSource<StateType, EventType>, TransitionTarget<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>>>
pub fn transitions(
&self
) -> Ref<'_, HashMap<TransitionSource<StateType, EventType>, TransitionTarget<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>>>
read only access to transition table so it can be traversed.
pub fn entry_exit_transitions(
&self
) -> Ref<'_, HashMap<EntryExitKey<StateType>, EntryExitTransition<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>>>
pub fn entry_exit_transitions(
&self
) -> Ref<'_, HashMap<EntryExitKey<StateType>, EntryExitTransition<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>>>
read only access to the entry/exit transition table.
pub fn add_enter_transition(
&mut self,
case: (StateType, EntryExit),
trans: EntryExitTransition<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>
) -> bool
pub fn add_enter_transition(
&mut self,
case: (StateType, EntryExit),
trans: EntryExitTransition<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>
) -> bool
new enter/exit transition per state executed after the transition right before the state is entered or called before transition on exit. If the machine remains in the same state neither the enter nor the exit transitions are called.
returns
- TRUE if transition has been inserted, FALSE if a
previous has been overwritten!
gives a read only peek into the extended state from the outside of transitions. Must be given up before running machine of course
check current state read-only
returns
- TRUE if machine has outstanding events queued to process
machine can be dotted if we have ordering on events & states
provides output of the FSM in dot format
filename
- optional filenamestate2name, event2name
- states to human readable name translationsomitstates, omitevents
- any transition starting/stopping on those states and the given events will be omitted from the representation
Trait Implementations
impl<ExtendedState, EventType, StateType, TransitionFnArguments, ErrorType> RunsFSM<EventType, StateType, TransitionFnArguments, ErrorType> for FSM<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType> where
StateType: Clone + PartialEq + Eq + Hash + Debug + Sized,
EventType: Clone + PartialEq + Eq + Hash + Debug + Sized,
ErrorType: Debug,
impl<ExtendedState, EventType, StateType, TransitionFnArguments, ErrorType> RunsFSM<EventType, StateType, TransitionFnArguments, ErrorType> for FSM<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType> where
StateType: Clone + PartialEq + Eq + Hash + Debug + Sized,
EventType: Clone + PartialEq + Eq + Hash + Debug + Sized,
ErrorType: Debug,
fn add_events(
&mut self,
events: &mut Vec<(EventType, OptionalFnArg<TransitionFnArguments>)>
) -> Result<u32, Errors<EventType, StateType, ErrorType>>
fn add_events(
&mut self,
events: &mut Vec<(EventType, OptionalFnArg<TransitionFnArguments>)>
) -> Result<u32, Errors<EventType, StateType, ErrorType>>
add events to the event queue @ the back, events are not processed
fn extend_events<I>(&mut self, events: I) where
I: IntoIterator<Item = (EventType, Option<TransitionFnArguments>)>,
fn extend_events<I>(&mut self, events: I) where
I: IntoIterator<Item = (EventType, Option<TransitionFnArguments>)>,
add events to the event queue @ the back from an iterator, events are not processed