pub struct FsmBuilder<S: Clone + Eq + Hash + 'static, D: Clone + 'static, M: 'static> { /* private fields */ }Expand description
Builder for a closure-driven FSM.
When(Idle) { case Go => goto(Running) using d+1 }
When(Running) { case Stop => goto(Idle) }
WhenUnhandled { case _ => stay() }
OnTransition { case Idle -> Running => log("starting") }
OnTermination { case _ => log("done") }Each when_state / whenever handler returns:
Some(FsmTransition)to transition.Noneto fall through towhenever, then to drop the message.
Implementations§
Source§impl<S, D, M> FsmBuilder<S, D, M>
impl<S, D, M> FsmBuilder<S, D, M>
pub fn new() -> Self
pub fn start_with(self, state: S, data: D) -> Self
Sourcepub fn when_state<F>(self, state: S, handler: F) -> Self
pub fn when_state<F>(self, state: S, handler: F) -> Self
Register a per-state handler. Overrides any existing handler for the same state.
Sourcepub fn whenever<F>(self, handler: F) -> Self
pub fn whenever<F>(self, handler: F) -> Self
Fallback handler. Runs when the per-state handler returns None.
pub fn on_transition<F>(self, hook: F) -> Self
pub fn on_termination<F>(self, hook: F) -> Self
pub fn build(self) -> Fsm<S, D, M>
Trait Implementations§
Auto Trait Implementations§
impl<S, D, M> Freeze for FsmBuilder<S, D, M>
impl<S, D, M> !RefUnwindSafe for FsmBuilder<S, D, M>
impl<S, D, M> Send for FsmBuilder<S, D, M>
impl<S, D, M> !Sync for FsmBuilder<S, D, M>
impl<S, D, M> Unpin for FsmBuilder<S, D, M>
impl<S, D, M> UnsafeUnpin for FsmBuilder<S, D, M>where
S: UnsafeUnpin,
D: UnsafeUnpin,
impl<S, D, M> !UnwindSafe for FsmBuilder<S, D, M>
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