pub struct StateMachine<State>where
    State: PartialEq + Eq + Hash,
{ /* private fields */ }

Implementations

Create new StateMachine and init start state

Examples
use StateMachine;

let mut machine = StateMachine::new(States::Empty)

Run state machine loop. if on_enter, update, or on_exit return false loop will be stopped

Run current state, if state can run

Examples
use Machine;
use StateMachine;

let mut machine = StateMachine::new(States::Empty);
machine.add(States::Empty, Box::new(EmptyImpl));
machine.add(States::Fire, Box::new(FireImpl));
machine.add(States::Stop, Box::new(StopImpl));

// Run empty state, and switch to next state
machine.next();

Add new state implementation to machine

If the machine did not have this state present, None is returned.

If the machine did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical. See the module-level documentation for more.

Examples
use Machine;
use StateMachine;

let mut machine = StateMachine::new(States::Empty);
machine.add(States::Fire, Box::new(FireStateImpl));

assert_eq!(machine.add(States::Fire, Box::new(StopStateImpl)), Some(Box<Machine<States>>));
assert_eq!(machine.add(&States::Block), None);

Add new machine

Example
let mut mach = StateMachine::new(1);

   mach
       .add_builder(2, State2)
       .add_builder(3, State3);

Remove state from machine, return the machine if the state was previously in machine

Examples
use Machine;
use StateMachine;

let mut machine = StateMachine::new(States::Empty);
machine.add(States::Fire, Box::new(FireStateImpl));

assert_eq!(machine.remove(&States::Fire), Some(Box<Machine<States>>));
assert_eq!(machine.remove(&States::Stop), None);

Returns true if the machine contains state.

Examples
use Machine;
use StateMachine;

let mut machine = StateMachine::new(States::Empty);
machine.add(States::Fire, Box::new(FireStateImpl));

assert_eq!(machine.contain(&States::Fire), true);
assert_eq!(machine.contain(&States::Stop), false);

Returns a reference to the value corresponding to the state.

Examples
use Machine;
use StateMachine;

let mut machine = StateMachine::new(States::Empty);
machine.add(States::Fire, Box::new(FireStateImpl));

assert_eq!(machine.contain(&States::Fire), true);
assert_eq!(machine.contain(&States::Stop), false);

assert_eq!(machine.get(&States::Fire), Some(&Box<Machine<States>>));
assert_eq!(machine.get(&States::Empty), None);

Return actual state machine state See full example in test. method ‘get’

Examples
use Machine;
use StateMachine;

let mut machine = StateMachine::new(States::Empty)
machine.add(States::Music, Box::new(MusicImpl));
machine.add(States::Empty, Box::new(EmptyImpl));

assert_eq!(*machine.get_state(), States::Empty);

machine.next();
assert_eq!(*machine.get_state(), States::Music);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.