Struct machinae::StateMachine [] [src]

pub struct StateMachine<A, E, F, S> { /* fields omitted */ }

A simple, generic state machine. The argument can be

  1. an owned value which implements Clone
  2. an immutable reference
  3. a mutable reference

In case 3 you need to specify the type of the state machine by either writing StateMachine<Ref<str>, _, _, _> or by using StateMachineRef.

Methods

impl<A, E, F, S> StateMachine<A, E, F, S>
[src]

[src]

Creates a new state machine with a give initial state.

[src]

Checks if the state machine is running.

impl<A, E, F, S> StateMachine<Ref<A>, E, F, S> where
    A: ?Sized,
    S: for<'a> State<&'a mut A, E, F>, 
[src]

[src]

Starts the state machine, calling .start on the initial state.

Panics

Panics if the state machine is running already.

[src]

Updates the current state by calling State::update with args.

Panics

Panics if the state machine is not running.

[src]

Performs a fixed update on the current state by calling State::fixed_update with args.

Panics

Panics if the state machine is not running.

[src]

Sends an event to the current state.

Panics

Panics if the state machine is not running.

[src]

Stops the state machine. This removes all states from the state machine and calls stop on them.

It is highly recommended that you call this method in case you want to stop the state machine, otherwise the states can't do anything on a shut down. If running() is false already, don't call this method.

Examples

while machine.running() {
    if shut_down_state_machine() {
        // If you end the machine yourself you should call
        machine.stop(());
        break;
    }
}
// If the loop exited because `machine.running()` was `false`,
// the machine is already stopped.

Panics

Panics if the state machine is not running.

impl<A, E, F, S> StateMachine<A, E, F, S> where
    A: Clone,
    S: State<A, E, F>, 
[src]

[src]

Starts the state machine, calling .start on the initial state.

Panics

Panics if the state machine is running already.

[src]

Updates the current state by calling State::update with args.

Panics

Panics if the state machine is not running.

[src]

Performs a fixed update on the current state by calling State::fixed_update with args.

Panics

Panics if the state machine is not running.

[src]

Sends an event to the current state.

Panics

Panics if the state machine is not running.

[src]

Stops the state machine. This removes all states from the state machine and calls stop on them.

It is highly recommended that you call this method in case you want to stop the state machine, otherwise the states can't do anything on a shut down. If running() is false already, don't call this method.

Examples

while machine.running() {
    if shut_down_state_machine() {
        // If you end the machine yourself you should call
        machine.stop(());
        break;
    }
}
// If the loop exited because `machine.running()` was `false`,
// the machine is already stopped.

Panics

Panics if the state machine is not running.

Trait Implementations

impl<A, E, F, S> Default for StateMachine<A, E, F, S> where
    S: Default
[src]

[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl<A, E, F, S> Send for StateMachine<A, E, F, S> where
    A: Send,
    E: Send,
    F: Send,
    S: Send

impl<A, E, F, S> Sync for StateMachine<A, E, F, S> where
    A: Sync,
    E: Sync,
    F: Sync,
    S: Sync