yarli_cli/yarli-core/src/fsm/
command.rs1use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
11#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
12pub enum CommandState {
13 CmdQueued,
14 CmdStarted,
15 CmdStreaming,
16 CmdExited,
17 CmdTimedOut,
18 CmdKilled,
19}
20
21impl CommandState {
22 pub fn is_terminal(self) -> bool {
24 matches!(
25 self,
26 CommandState::CmdExited | CommandState::CmdTimedOut | CommandState::CmdKilled
27 )
28 }
29
30 pub fn valid_transitions(self) -> &'static [CommandState] {
32 use CommandState::*;
33 match self {
34 CmdQueued => &[CmdStarted, CmdKilled],
35 CmdStarted => &[CmdStreaming, CmdExited, CmdTimedOut, CmdKilled],
36 CmdStreaming => &[CmdExited, CmdTimedOut, CmdKilled],
37 CmdExited => &[],
38 CmdTimedOut => &[],
39 CmdKilled => &[],
40 }
41 }
42
43 pub fn can_transition_to(self, target: CommandState) -> bool {
45 self.valid_transitions().contains(&target)
46 }
47}