Skip to main content

fips_core/node/
state.rs

1use super::*;
2
3/// Node operational state.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum NodeState {
6    /// Created but not started.
7    Created,
8    /// Starting up (initializing transports).
9    Starting,
10    /// Fully operational.
11    Running,
12    /// Shutting down.
13    Stopping,
14    /// Stopped.
15    Stopped,
16}
17
18impl NodeState {
19    /// Check if node is operational.
20    pub fn is_operational(&self) -> bool {
21        matches!(self, NodeState::Running)
22    }
23
24    /// Check if node can be started.
25    pub fn can_start(&self) -> bool {
26        matches!(self, NodeState::Created | NodeState::Stopped)
27    }
28
29    /// Check if node can be stopped.
30    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}