Skip to main content

transition

Function transition 

Source
pub const fn transition<M, C, E>(target: M) -> Decision<M, C, E>
Expand description

Creates a decision that transitions to the given mode.

This is a free function wrapper around Decision::transition. It exists to make match arms read like a sentence.

use ready_active_safe::prelude::*;

let d: Decision<&str, (), ()> = transition("active");
assert_eq!(d.target_mode(), Some(&"active"));
Examples found in repository?
examples/runner.rs (line 53)
47    fn on_event(&self, mode: &Mode, event: &Event) -> Decision<Mode, Command> {
48        use Command::*;
49        use Event::*;
50        use Mode::*;
51
52        match (mode, event) {
53            (Ready, Start) => transition(Active).emit(Init),
54            (Active, Reset) => transition(Ready),
55            (Active, Fault) => transition(Safe).emit(Shutdown),
56            _ => ignore(),
57        }
58    }
More examples
Hide additional examples
examples/metrics.rs (line 58)
52    fn on_event(&self, mode: &Mode, event: &Event) -> Decision<Mode, Command> {
53        use Command::*;
54        use Event::*;
55        use Mode::*;
56
57        match (mode, event) {
58            (Ready, Start) => transition(Active).emit(Initialize),
59            (Active, Fault) => transition(Safe).emit(EmergencyStop),
60            (Safe, Recover) => transition(Ready).emit(Reset),
61            _ => ignore(),
62        }
63    }
examples/recovery_cycle.rs (line 55)
49    fn on_event(&self, mode: &Mode, event: &Event) -> Decision<Mode, Command> {
50        use Command::*;
51        use Event::*;
52        use Mode::*;
53
54        match (mode, event) {
55            (Ready, Activate) => transition(Active).emit(StartWork),
56            (Active, Fault) => transition(Safe).emit(EnterSafeState),
57            (Safe, RecoveryComplete) => transition(Ready).emit(ResetHardware),
58            _ => ignore(),
59        }
60    }
examples/channel_runtime.rs (line 60)
54    fn on_event(&self, mode: &Mode, event: &Event) -> Decision<Mode, Command> {
55        use Command::*;
56        use Event::*;
57        use Mode::*;
58
59        match (mode, event) {
60            (Initializing, Tick) => transition(Sampling),
61            (Sampling, Measurement(val)) => stay().emit(RecordSample(*val)),
62            (Sampling, Tick) => stay().emit(LogTick),
63            (Sampling, Fault) => transition(Safe).emit(TriggerAlarm),
64            _ => ignore(),
65        }
66    }
examples/basic.rs (line 60)
49    fn on_event(
50        &self,
51        mode: &Self::Mode,
52        event: &Self::Event,
53    ) -> Decision<Self::Mode, Self::Command> {
54        use Command::*;
55        use Event::*;
56        use Mode::*;
57
58        match (mode, event) {
59            (Ready, Initialize) => stay().emit(RunDiagnostics),
60            (Ready, Start) => transition(Active).emit(BeginProcessing),
61            (Active, Fault) => transition(Safe).emit_all([FlushBuffers, NotifyOperator]),
62            _ => ignore(),
63        }
64    }
examples/replay.rs (line 66)
55    fn on_event(
56        &self,
57        mode: &Self::Mode,
58        event: &Self::Event,
59    ) -> Decision<Self::Mode, Self::Command> {
60        use Command::*;
61        use Event::*;
62        use Mode::*;
63
64        match (mode, event) {
65            (Ready, PowerOn) => stay().emit(InitializeSensors),
66            (Ready, BeginMeasurement) => transition(Active).emit(StartDataAcquisition),
67            (Active, DataCollected) => stay().emit(StoreReading),
68            (Active, AnomalyDetected) => transition(Safe).emit(TriggerAlarm),
69            (Safe, OperatorReset) => transition(Ready).emit_all([ClearAlarm, RecalibrateSensors]),
70            _ => ignore(),
71        }
72    }