pub struct StateMachine<'b, T: ?Sized> { /* private fields */ }Expand description
Wrapper type for custom state machines generated through the
fsm macro.
Implementations§
Source§impl<T> StateMachine<'static, T>
impl<T> StateMachine<'static, T>
Source§impl<'b, T: FSM> StateMachine<'b, T>
impl<'b, T: FSM> StateMachine<'b, T>
Sourcepub fn token(&self, once: Ephemeral<'b>) -> T::Token<'b>
pub fn token(&self, once: Ephemeral<'b>) -> T::Token<'b>
Returns an enumeration containing token witnesses for the current state.
Sourcepub fn erased(&self) -> T::Erased
pub fn erased(&self) -> T::Erased
Returns a type-erased version of the current state, i.e. an enumeration of just the states, without additional payload.
Sourcepub fn transition<U, V>(&self, curr: U, data: T::Data) -> Vwhere
T: Transition<'b, U, V>,
pub fn transition<U, V>(&self, curr: U, data: T::Data) -> Vwhere
T: Transition<'b, U, V>,
Performs a state transition given the current state and the payload of the follow-up state, returning a token witness for the next state.
This method will panic if the transition would invalidate other token
witnesses. See Self::try_transition for a non-panicking variant.
Sourcepub fn try_transition<U, V>(
&self,
curr: U,
data: T::Data,
) -> Result<V, TransitionError<U>>where
T: Transition<'b, U, V>,
pub fn try_transition<U, V>(
&self,
curr: U,
data: T::Data,
) -> Result<V, TransitionError<U>>where
T: Transition<'b, U, V>,
Attempts to perform a state transition given the current state and the payload of the follow-up state, returning a token witness for the next state if successful and the previous token witness on error.
It is not possible to transition if other token witnesses for the same
state machine would be invalidated by the transition. If you simply
want to update the data associated with a state without changing it,
consider using Self::update which doesn’t have this restriction.
Sourcepub fn update<U>(&self, curr: U, data: T::Data) -> Uwhere
T: Transition<'b, U, U>,
pub fn update<U>(&self, curr: U, data: T::Data) -> Uwhere
T: Transition<'b, U, U>,
Updates the internal data of a state without changing it.
This is allowed, even if other token witnesses exist as it cannot invalidate them and will only panic if the state cannot be modified due to being borrowed already.
Trait Implementations§
Source§impl<T: Default> Default for StateMachine<'static, T>
impl<T: Default> Default for StateMachine<'static, T>
Source§impl<'b, T> Rebrand<'b> for StateMachine<'b, T>
impl<'b, T> Rebrand<'b> for StateMachine<'b, T>
Source§type Kind<'a> = StateMachine<'a, T>
type Kind<'a> = StateMachine<'a, T>
Self and forces
the type to correspond with the Self type for one of the brandings. Read moreSource§fn identity_ref(&self) -> &Self::Kind<'brand>
fn identity_ref(&self) -> &Self::Kind<'brand>
Self into a reference of Self::Kind, which
is constrained to be a reference to Self itself, making this a no-op. Read moreSource§fn identity_mut(&mut self) -> &mut Self::Kind<'brand>
fn identity_mut(&mut self) -> &mut Self::Kind<'brand>
Self into a mutable reference of
Self::Kind, which is constrained to be a mutable reference to Self
itself, making this a no-op. Read more