Struct machinae::StateMachine
[−]
[src]
pub struct StateMachine<A, E, F, S> { /* fields omitted */ }
A simple, generic state machine. The argument can be
- an owned value which implements
Clone
- an immutable reference
- 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]
pub fn new(initial: S) -> Self
[src]
Creates a new state machine with a give initial
state.
pub fn running(&self) -> bool
[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]
A: ?Sized,
S: for<'a> State<&'a mut A, E, F>,
pub fn start(&mut self, args: &mut A) -> Result<(), E>
[src]
Starts the state machine, calling .start
on the initial state.
Panics
Panics if the state machine is running already.
pub fn update(&mut self, args: &mut A) -> Result<(), E>
[src]
Updates the current state by calling State::update
with args
.
Panics
Panics if the state machine is not running.
pub fn fixed_update(&mut self, args: &mut A) -> Result<(), E>
[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.
pub fn event(&mut self, args: &mut A, event: F) -> Result<(), E>
[src]
pub fn stop(&mut self, args: &mut A)
[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]
A: Clone,
S: State<A, E, F>,
pub fn start(&mut self, args: A) -> Result<(), E>
[src]
Starts the state machine, calling .start
on the initial state.
Panics
Panics if the state machine is running already.
pub fn update(&mut self, args: A) -> Result<(), E>
[src]
Updates the current state by calling State::update
with args
.
Panics
Panics if the state machine is not running.
pub fn fixed_update(&mut self, args: A) -> Result<(), E>
[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.
pub fn event(&mut self, args: A, event: F) -> Result<(), E>
[src]
pub fn stop(&mut self, args: A)
[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]
S: Default,