Trait State

Source
pub trait State {
    // Provided methods
    fn entry(&mut self) { ... }
    fn execute(&mut self) { ... }
    fn exit(&mut self) { ... }
}
Expand description

Trait that must be implemented by all states

Allows to define behavior when entering, exiting and running the state. Both the entry and exit function will only be executed once for each state. The execute function will be executed as long as the state does not transition into another state. There can only ever be one single state active.

Provided Methods§

Source

fn entry(&mut self)

Implement any behavior that hast to be executed when entering the state.

    fn entry(&mut self) {
        println!("Called right after being transitioned into");
    }
Source

fn execute(&mut self)

Implement any behavior that has to be executed when the state is being executed. This function will be called as long as the state does not transit.

    fn execute(&mut self) {
        println!("Called during every step");
    }
Source

fn exit(&mut self)

Implement any behavior that hast to be executed when exiting the state.

    fn exit(&mut self) {
        println!("Called before transitioning to another state");
    }

Implementors§