Skip to main content

StateMachine

Struct StateMachine 

Source
pub struct StateMachine<S, C> { /* private fields */ }
Expand description

Typed state machine with guarded transitions, audit, and persistence hooks.

Implementations§

Source§

impl<S, C> StateMachine<S, C>
where S: State + Eq + Hash, C: Clone + Send + Sync + 'static,

Source

pub fn new(initial: S) -> Self

Create a state machine with an initial state.

Source

pub fn with_transition(self, transition: Transition<S, C>) -> Self

Register a transition.

Source

pub fn with_persistence( self, persistence: Arc<dyn StatePersistence<S, C>>, ) -> Self

Register a persistence hook.

Source

pub fn state(&self) -> S

Return the current state.

Source

pub fn snapshot(&self) -> StateSnapshot<S>

Return the current snapshot.

Source

pub fn audit_log(&self) -> Vec<AuditEntry<S, C>>

Return a copy of the audit log.

Source

pub fn apply(&self, name: &str, context: C) -> AppResult<StateSnapshot<S>>

Apply a named transition.

Auto Trait Implementations§

§

impl<S, C> !Freeze for StateMachine<S, C>

§

impl<S, C> !RefUnwindSafe for StateMachine<S, C>

§

impl<S, C> !UnwindSafe for StateMachine<S, C>

§

impl<S, C> Send for StateMachine<S, C>
where S: Send, C: Send,

§

impl<S, C> Sync for StateMachine<S, C>
where S: Send + Sync, C: Send,

§

impl<S, C> Unpin for StateMachine<S, C>
where S: Unpin, C: Unpin,

§

impl<S, C> UnsafeUnpin for StateMachine<S, C>
where S: UnsafeUnpin,

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.