pub struct StateMachineBuilder<Event, State, Store> { /* private fields */ }Expand description
StateMachineBuilder is used to build a StateMachine.
§Example
use fluent_state_machine::StateMachineBuilder;
let mut turnstyle = StateMachineBuilder::new((), "Locked")
.state("Locked")
.on("Coin").go_to("Unlocked")
.state("Unlocked")
.on("Push").go_to("Locked")
.build().unwrap();
turnstyle.trigger("Coin");
assert_eq!(turnstyle.state, "Unlocked");
turnstyle.trigger("Push");
assert_eq!(turnstyle.state, "Locked");Implementations§
Source§impl<Event, State, Store> StateMachineBuilder<Event, State, Store>
impl<Event, State, Store> StateMachineBuilder<Event, State, Store>
pub fn new(data_store: Store, initial_state: State) -> Self
pub fn set_global_action( self, global_action: fn(&mut Store, &State, &Event), ) -> Self
pub const fn state(self, state: State) -> Self
pub fn on(self, event: Event) -> Self
pub fn go_to(self, target: State) -> Self
pub fn update(self, before_event: fn(&mut Store)) -> Self
pub fn only_if(self, condition: fn(&Store) -> bool) -> Self
pub fn then(self, after_event: fn(&mut Store)) -> Self
pub fn build( self, ) -> Result<StateMachine<Event, State, Store>, Vec<StateMachineError>>
Auto Trait Implementations§
impl<Event, State, Store> Freeze for StateMachineBuilder<Event, State, Store>
impl<Event, State, Store> RefUnwindSafe for StateMachineBuilder<Event, State, Store>
impl<Event, State, Store> Send for StateMachineBuilder<Event, State, Store>
impl<Event, State, Store> Sync for StateMachineBuilder<Event, State, Store>
impl<Event, State, Store> Unpin for StateMachineBuilder<Event, State, Store>
impl<Event, State, Store> UnwindSafe for StateMachineBuilder<Event, State, Store>
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