pub struct StateMachineBuilder<S, E>{ /* private fields */ }Expand description
Builder used to define and validate finite state machine rules.
S is the state type and E is the event type. Configuration methods
consume and return the builder so rule definitions can be chained. The built
StateMachine is immutable.
Implementations§
Source§impl<S, E> StateMachineBuilder<S, E>
impl<S, E> StateMachineBuilder<S, E>
Sourcepub fn add_states(self, states: &[S]) -> Self
pub fn add_states(self, states: &[S]) -> Self
Sourcepub fn set_initial_state(self, state: S) -> Self
pub fn set_initial_state(self, state: S) -> Self
Marks a state as an initial state.
The state must also be registered through add_state
or add_states before build is
called.
§Parameters
state: Initial state to add.
§Returns
The updated builder.
Sourcepub fn set_initial_states(self, states: &[S]) -> Self
pub fn set_initial_states(self, states: &[S]) -> Self
Sourcepub fn set_final_state(self, state: S) -> Self
pub fn set_final_state(self, state: S) -> Self
Marks a state as a final state.
The state must also be registered through add_state
or add_states before build is
called.
§Parameters
state: Final state to add.
§Returns
The updated builder.
Sourcepub fn set_final_states(self, states: &[S]) -> Self
pub fn set_final_states(self, states: &[S]) -> Self
Sourcepub fn add_transition(self, source: S, event: E, target: S) -> Self
pub fn add_transition(self, source: S, event: E, target: S) -> Self
Adds a transition by source state, event, and target state.
Source and target states must be registered before
build is called. Adding the same transition more than
once is allowed. Adding the same (source, event) with a different
target is rejected during build.
§Parameters
source: State before the event is applied.event: Event that triggers the transition.target: State after the transition succeeds.
§Returns
The updated builder.
Sourcepub fn add_transition_value(self, transition: Transition<S, E>) -> Self
pub fn add_transition_value(self, transition: Transition<S, E>) -> Self
Sourcepub fn build(self) -> Result<StateMachine<S, E>, StateMachineBuildError<S, E>>
pub fn build(self) -> Result<StateMachine<S, E>, StateMachineBuildError<S, E>>
Builds an immutable state machine after validating the rule set.
§Returns
A validated immutable state machine.
§Errors
Returns a StateMachineBuildError when an initial state, final state,
transition source, or transition target is not registered, or when two
transitions map the same (source, event) pair to different targets.
Trait Implementations§
Source§impl<S, E> Clone for StateMachineBuilder<S, E>
impl<S, E> Clone for StateMachineBuilder<S, E>
Source§fn clone(&self) -> StateMachineBuilder<S, E>
fn clone(&self) -> StateMachineBuilder<S, E>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more