Skip to main content

StateMachineBuilder

Trait StateMachineBuilder 

Source
pub trait StateMachineBuilder<T, U, V, W>
where T: StateEnum, U: StateMachineEvent, V: TopState, W: StateMachine<T, U, V>,
{ // Required methods fn new(top_state: V) -> Self; fn name(self, name: String) -> Self; fn build(self) -> W; }
Expand description

Builder for a StateMachine.

Required Methods§

Source

fn new(top_state: V) -> Self

Make a new StateMachineBuilder from a TopState.

§Example
#[moku::state_machine]
mod example {
    #[moku::machine_module]
    pub mod machine {}

    use machine::State;

    pub struct Top;

    impl moku::TopState for Top {}
}

use moku::StateMachineBuilder;
use example::machine::Builder;

let builder = Builder::new(example::Top);
let machine = builder.build();
Source

fn name(self, name: String) -> Self

Available on crate feature std only.

Set the name of the StateMachine.

If not set, defaults to the state_machine module’s name in UpperCamel case.

§Example
let machine = Builder::new(example::Top).name("Kikai".to_owned()).build();
assert_eq!(machine.name(), "Kikai");
Source

fn build(self) -> W

Build the StateMachine.

§Example
#[moku::state_machine]
mod example {
    #[moku::machine_module]
    pub mod machine {}

    use machine::State;

    pub struct Top;

    impl moku::TopState for Top {}
}

use moku::StateMachineBuilder;
use example::machine::Builder;

let builder = Builder::new(example::Top);
let machine = builder.build();

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§