Struct StateMachine

Source
pub struct StateMachine<T: StateMachineImpl> { /* private fields */ }
Expand description

Encapsulates the state and other SM data and expose transition functions.

Implementations§

Source§

impl<T> StateMachine<T>
where T: StateMachineImpl,

Source

pub fn new(data: T, initial_state: T::InitialState) -> Self

Create a new instance of this wrapper which encapsulates the initial state.

Source

pub fn step(&mut self)

Only change the state, do not accept any input and do not produce any output.

Source

pub fn produce<O: From<T::Output>>(&mut self) -> O

Produce an output, given no input.

Source

pub fn consume<I: Into<T::Input>>(&mut self, input: I)

Consume an input, do not care about the output.

Source

pub fn relay<I: Into<T::Input>, O: From<T::Output>>(&mut self, input: I) -> O

Consume an input, produce an output.

Source

pub fn can_step(&mut self) -> bool

Source

pub fn can_produce<O>(&mut self) -> bool
where O: Enumerated<T::Output>,

Source

pub fn can_consume<I>(&mut self) -> bool
where I: Enumerated<T::Input>,

Source

pub fn can_relay<I, O>(&mut self) -> bool
where I: Enumerated<T::Input>, O: Enumerated<T::Output>,

Source

pub fn state(&self) -> &T::State

Returns the current state.

Source

pub fn data(&self) -> &T

Auto Trait Implementations§

§

impl<T> Freeze for StateMachine<T>
where T: Freeze, <T as StateMachineImpl>::State: Freeze,

§

impl<T> RefUnwindSafe for StateMachine<T>
where T: RefUnwindSafe, <T as StateMachineImpl>::State: RefUnwindSafe,

§

impl<T> Send for StateMachine<T>
where T: Send, <T as StateMachineImpl>::State: Send,

§

impl<T> Sync for StateMachine<T>
where T: Sync, <T as StateMachineImpl>::State: Sync,

§

impl<T> Unpin for StateMachine<T>
where T: Unpin, <T as StateMachineImpl>::State: Unpin,

§

impl<T> UnwindSafe for StateMachine<T>
where T: UnwindSafe, <T as StateMachineImpl>::State: 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.