FSM

Struct FSM 

Source
pub struct FSM<State, Effect>
where State: Eq + PartialEq + Copy + Hash, Effect: Copy,
{ /* private fields */ }
Expand description

Finite state machine with side effects (Mealy automata)

Implementations§

Source§

impl<State, Effect> FSM<State, Effect>
where State: Eq + PartialEq + Copy + Hash + Debug, Effect: Copy,

Source

pub fn new<'a>( initial_state: State, transition_table: HashMap<State, Vec<Transition<State, Effect>>>, post_effect: Option<Effect>, ) -> Result<Self, FSMError<'a, State>>

Creates new instance of FSM

  • initial_state: starting state,
  • transition_table: transition graph
  • post_effect: post-effect
Source

pub fn merge_effects<'a>( &mut self, effects_map: &HashMap<StatesConnection<State>, Vec<Effect>>, ) -> Result<(), FSMError<'a, State>>

Merges effects into existing fsm for its states aligned to order of transitions for each state

  • effects_map: map from pair of states (“from”, “to”) to ordered list of effects (This method is created mainly for testing, reusing the same states and transition rules (i.e. partial fsm) for different effects configurations. For typical cases, it’s recommended to build fsm from its initialization (i.e. using “new” method))
Source

pub fn proceed<'a>( &self, string: &'a String, effector: Option<&'a mut dyn Effector<Effect>>, ) -> Result<(), FSMError<'a, State>>

Runs some string through FSM to validate it (and apply some effects)

  • string: runnable string,
  • effector: module that mutates some data by effects

Auto Trait Implementations§

§

impl<State, Effect> Freeze for FSM<State, Effect>
where State: Freeze, Effect: Freeze,

§

impl<State, Effect> RefUnwindSafe for FSM<State, Effect>
where State: RefUnwindSafe, Effect: RefUnwindSafe,

§

impl<State, Effect> Send for FSM<State, Effect>
where State: Send, Effect: Send,

§

impl<State, Effect> Sync for FSM<State, Effect>
where State: Sync, Effect: Sync,

§

impl<State, Effect> Unpin for FSM<State, Effect>
where State: Unpin, Effect: Unpin,

§

impl<State, Effect> UnwindSafe for FSM<State, Effect>
where State: UnwindSafe, Effect: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.