Skip to main content

StateMachine

Struct StateMachine 

Source
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>

Source

pub const fn new(inner: T) -> Self

Creates a new state machine using the state T.

Source§

impl<'b, T: FSM> StateMachine<'b, T>

Source

pub fn token(&self, once: Ephemeral<'b>) -> T::Token<'b>

Returns an enumeration containing token witnesses for the current state.

Source

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.

Source

pub fn label(&self) -> &'static str

Returns the name of the current state as a string.

Source

pub fn transition<U, V>(&self, curr: U, data: T::Data) -> V
where 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.

Source

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.

Source

pub fn update<U>(&self, curr: U, data: T::Data) -> U
where 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.

Source

pub fn borrow(&self) -> Ref<'_, T>

Borrows the inner state.

Trait Implementations§

Source§

impl<T: Default> Default for StateMachine<'static, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'b, T> Rebrand<'b> for StateMachine<'b, T>

Source§

type Kind<'a> = StateMachine<'a, T>

Meta function that computes the rebranded version of Self and forces the type to correspond with the Self type for one of the brandings. Read more
Source§

fn identity_ref(&self) -> &Self::Kind<'brand>

“Converts” a reference to Self into a reference of Self::Kind, which is constrained to be a reference to Self itself, making this a no-op. Read more
Source§

fn identity_mut(&mut self) -> &mut Self::Kind<'brand>

“Converts” a mutable reference to 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
Source§

impl<'b, T> Stateful for StateMachine<'b, T>

Source§

type Brand = &'b ()

Associated marker type for the branding.
Source§

unsafe fn enter(&self)

Method hook used to register the creation of another Ephemeral-token for this instance. Read more
Source§

unsafe fn leave(&self)

Method hook used to register the destruction of a Ephemeral-token for this instance. Read more

Auto Trait Implementations§

§

impl<'b, T> !Freeze for StateMachine<'b, T>

§

impl<'b, T> !RefUnwindSafe for StateMachine<'b, T>

§

impl<'b, T> !Sync for StateMachine<'b, T>

§

impl<'b, T> Send for StateMachine<'b, T>
where T: Send + ?Sized,

§

impl<'b, T> Unpin for StateMachine<'b, T>
where T: Unpin + ?Sized,

§

impl<'b, T> UnsafeUnpin for StateMachine<'b, T>
where T: UnsafeUnpin + ?Sized,

§

impl<'b, T> UnwindSafe for StateMachine<'b, T>
where T: UnwindSafe + ?Sized,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more