Struct wlan_statemachine::StateMachine
source · pub struct StateMachine<S> { /* private fields */ }
Expand description
Wrapper to safely replace states of state machine which don’t consume their states. Use this wrapper if state transitions are performed on mutable references rather than consumed states. Example:
fn on_event(event: Event, statemachine: &mut StateMachine<Foo>) {
statemachine.replace_state(|state| match state {
State::A(_) => match event {
Event::A => State::B,
_ => state,
}
State::B => {
warn!("cannot receive events in State::B");
state
}
})
}
Implementations§
source§impl<S> StateMachine<S>
impl<S> StateMachine<S>
sourcepub fn replace_state<F>(&mut self, map: F) -> &mut Selfwhere
F: FnOnce(S) -> S,
pub fn replace_state<F>(&mut self, map: F) -> &mut Selfwhere F: FnOnce(S) -> S,
Replaces the current state with one lazily constructed by map
.
sourcepub fn replace_state_with(&mut self, new_state: S) -> &mut Self
pub fn replace_state_with(&mut self, new_state: S) -> &mut Self
Replaces the current state with new_state
.
sourcepub fn into_state(self) -> S
pub fn into_state(self) -> S
Consumes the state machine and returns its current state.