Skip to main content

StateMachine

Struct StateMachine 

Source
pub struct StateMachine<Ctx, S: ?Sized> { /* private fields */ }
Expand description

Queue-based state machine interpreter.

Processes a sequence of State objects, collecting key-value outputs into a JSON map. When every state has completed and the queue is empty, advance() returns Some(Value) containing the accumulated results.

Implementations§

Source§

impl<Ctx, S: State<Ctx, S> + ?Sized> StateMachine<Ctx, S>

Source

pub fn new(queue: VecDeque<Box<S>>) -> Self

Source

pub fn start(&mut self, ctx: &Ctx) -> Option<Value>

Activate the first state in the queue.

Returns Some(Value) immediately if the queue is empty (nothing to do), or None if a state was activated and the machine is running.

Source

pub fn advance(&mut self, action: Option<Action>, ctx: &Ctx) -> Option<Value>

Step the machine forward by dispatching an optional action to the current state. None action triggers a tick; Some(action) triggers handle_action.

Returns None while the machine is still running, or Some(Value) with the accumulated results when every state has completed.

Source

pub fn current_state(&self) -> Option<&S>

Source

pub fn current_state_mut(&mut self) -> Option<&mut S>

Source

pub fn finish(&mut self) -> Value

Drain the machine and return accumulated results immediately.

Auto Trait Implementations§

§

impl<Ctx, S> Freeze for StateMachine<Ctx, S>
where S: ?Sized,

§

impl<Ctx, S> RefUnwindSafe for StateMachine<Ctx, S>
where S: RefUnwindSafe + ?Sized,

§

impl<Ctx, S> Send for StateMachine<Ctx, S>
where S: Send + ?Sized,

§

impl<Ctx, S> Sync for StateMachine<Ctx, S>
where S: Sync + ?Sized,

§

impl<Ctx, S> Unpin for StateMachine<Ctx, S>
where S: ?Sized,

§

impl<Ctx, S> UnsafeUnpin for StateMachine<Ctx, S>
where S: ?Sized,

§

impl<Ctx, S> UnwindSafe for StateMachine<Ctx, S>
where S: 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, 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.