Skip to main content

StateMachineBuilder

Struct StateMachineBuilder 

Source
pub struct StateMachineBuilder<S, E>
where S: Copy + Eq + Hash + Debug, E: Copy + Eq + Hash + Debug,
{ /* 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>
where S: Copy + Eq + Hash + Debug + 'static, E: Copy + Eq + Hash + Debug + 'static,

Source

pub fn new() -> Self

Creates an empty state machine builder.

§Returns

A builder with no states or transitions.

Source

pub fn add_state(self, state: S) -> Self

Adds a state to the state machine definition.

§Parameters
  • state: State to register.
§Returns

The updated builder.

Source

pub fn add_states(self, states: &[S]) -> Self

Adds multiple states to the state machine definition.

§Parameters
  • states: States to register.
§Returns

The updated builder.

Source

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.

Source

pub fn set_initial_states(self, states: &[S]) -> Self

Marks multiple states as initial states.

§Parameters
  • states: Initial states to add.
§Returns

The updated builder.

Source

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.

Source

pub fn set_final_states(self, states: &[S]) -> Self

Marks multiple states as final states.

§Parameters
  • states: Final states to add.
§Returns

The updated builder.

Source

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.

Source

pub fn add_transition_value(self, transition: Transition<S, E>) -> Self

Adds a transition value.

§Parameters
  • transition: Transition to add to the state machine definition.
§Returns

The updated builder.

Source

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>
where S: Copy + Eq + Hash + Debug + Clone, E: Copy + Eq + Hash + Debug + Clone,

Source§

fn clone(&self) -> StateMachineBuilder<S, E>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S, E> Debug for StateMachineBuilder<S, E>
where S: Copy + Eq + Hash + Debug + Debug, E: Copy + Eq + Hash + Debug + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S, E> Default for StateMachineBuilder<S, E>
where S: Copy + Eq + Hash + Debug + 'static, E: Copy + Eq + Hash + Debug + 'static,

Source§

fn default() -> Self

Creates an empty state machine builder.

Auto Trait Implementations§

§

impl<S, E> Freeze for StateMachineBuilder<S, E>

§

impl<S, E> RefUnwindSafe for StateMachineBuilder<S, E>

§

impl<S, E> Send for StateMachineBuilder<S, E>
where S: Send, E: Send,

§

impl<S, E> Sync for StateMachineBuilder<S, E>
where S: Sync, E: Sync,

§

impl<S, E> Unpin for StateMachineBuilder<S, E>
where S: Unpin, E: Unpin,

§

impl<S, E> UnsafeUnpin for StateMachineBuilder<S, E>

§

impl<S, E> UnwindSafe for StateMachineBuilder<S, E>
where S: UnwindSafe, E: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoResult<T> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.