Trait Action

Source
pub trait Action {
    type Input;

    // Required method
    fn execute(&self, input: &mut Self::Input);
}
Expand description

Action that may be executed when entering a state.

See ActionMut if you need an action that may mutate its internal state. The Action is implemented for Box<Fn(T)> by default.

Required Associated Types§

Source

type Input

Input type for the action.

Required Methods§

Source

fn execute(&self, input: &mut Self::Input)

Perform the action in the input.

Note that the input takes the input type as a reference to allow multiple actions to be executed on it if necessary. This doesn’t prevent mutating the input though, since the Input itself can be defined as &mut Foo.

§Examples
struct IncrementValue;
impl Action for IncrementValue {
    type Input = u32;
    fn execute(&self, input: &mut Self::Input) {
        *input += 1;
    }
}

Implementations on Foreign Types§

Source§

impl<T> Action for Box<dyn Fn(&mut T)>

Source§

type Input = T

Source§

fn execute(&self, input: &mut T)

Implementors§