Trait StateRef
Source pub trait StateRef<T: StateEnum, U: State<T>> {
// Required methods
fn state_ref(&self) -> Option<&U>;
fn state_mut(&mut self) -> Option<&mut U>;
}
Expand description
Trait for getting references to active states.
Will be implemented by a StateMachine for every one of its states.
Get a reference to the state, if currently active.
Returns None if the state machine is not currently in the state.
§Example
pub struct Foo;
#[superstate(Top)]
impl State<ExampleState> for Foo {}
let foo: Option<&Foo> = machine.state_ref();
Get a mutable reference to the state.
Returns None if the state machine is not currently in the state.
§Example
pub struct Foo;
#[superstate(Top)]
impl State<ExampleState> for Foo {}
let foo: Option<&mut Foo> = machine.state_mut();