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>
impl<Ctx, S: State<Ctx, S> + ?Sized> StateMachine<Ctx, S>
pub fn new(queue: VecDeque<Box<S>>) -> Self
Sourcepub fn start(&mut self, ctx: &Ctx) -> Option<Value>
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.
Sourcepub fn advance(&mut self, action: Option<Action>, ctx: &Ctx) -> Option<Value>
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.
pub fn current_state(&self) -> Option<&S>
pub fn current_state_mut(&mut self) -> Option<&mut S>
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>
impl<Ctx, S> Sync for StateMachine<Ctx, S>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more