use super::*;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NodeState {
Created,
Starting,
Running,
Stopping,
Stopped,
}
impl NodeState {
pub fn is_operational(&self) -> bool {
matches!(self, NodeState::Running)
}
pub fn can_start(&self) -> bool {
matches!(self, NodeState::Created | NodeState::Stopped)
}
pub fn can_stop(&self) -> bool {
matches!(self, NodeState::Running)
}
}
impl fmt::Display for NodeState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
NodeState::Created => "created",
NodeState::Starting => "starting",
NodeState::Running => "running",
NodeState::Stopping => "stopping",
NodeState::Stopped => "stopped",
};
write!(f, "{}", s)
}
}