1use super::*;
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum NodeState {
6 Created,
8 Starting,
10 Running,
12 Stopping,
14 Stopped,
16}
17
18impl NodeState {
19 pub fn is_operational(&self) -> bool {
21 matches!(self, NodeState::Running)
22 }
23
24 pub fn can_start(&self) -> bool {
26 matches!(self, NodeState::Created | NodeState::Stopped)
27 }
28
29 pub fn can_stop(&self) -> bool {
31 matches!(self, NodeState::Running)
32 }
33}
34
35impl fmt::Display for NodeState {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 let s = match self {
38 NodeState::Created => "created",
39 NodeState::Starting => "starting",
40 NodeState::Running => "running",
41 NodeState::Stopping => "stopping",
42 NodeState::Stopped => "stopped",
43 };
44 write!(f, "{}", s)
45 }
46}