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§
source§impl<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType> FSM<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>where
StateType: Clone + Eq + Hash + Sized,
EventType: Clone + Eq + Hash + Sized,
impl<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType> FSM<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>where
StateType: Clone + Eq + Hash + Sized,
EventType: Clone + Eq + Hash + Sized,
implementation of methods to contstruct the machine
sourcepub fn new(
start_state: StateType,
extended_init: Box<ExtendedState>,
name: &str,
log: Option<Logger>
) -> Self
pub fn new(
start_state: StateType,
extended_init: Box<ExtendedState>,
name: &str,
log: Option<Logger>
) -> Self
new FSM with an initial extended state box’ed up so it can be passed around easily
sourcepub fn flyweight(
&self,
extended_init: Box<ExtendedState>,
name: &str,
log: Option<Logger>
) -> Self
pub fn flyweight(
&self,
extended_init: Box<ExtendedState>,
name: &str,
log: Option<Logger>
) -> Self
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.
sourcepub 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!
sourcepub 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.
sourcepub 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.
sourcepub 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!
pub fn name(&self) -> &String
sourcepub fn extended_state(&self) -> Ref<'_, Box<ExtendedState>>
pub fn extended_state(&self) -> Ref<'_, Box<ExtendedState>>
gives a read only peek into the extended state from the outside of transitions. Must be given up before running machine of course
sourcepub fn current_state(&self) -> StateType
pub fn current_state(&self) -> StateType
check current state read-only
sourcepub fn events_pending(&self) -> bool
pub fn events_pending(&self) -> bool
returns
- TRUE if machine has outstanding events queued to process
source§impl<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType> FSM<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>where
StateType: Clone + Eq + Ord + Hash + Sized,
EventType: Clone + Eq + Ord + Hash + Sized,
impl<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType> FSM<ExtendedState, StateType, EventType, TransitionFnArguments, ErrorType>where
StateType: Clone + Eq + Ord + Hash + Sized,
EventType: Clone + Eq + Ord + Hash + Sized,
machine can be dotted if we have ordering on events & states