use strum::Display;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Display)]
#[strum(serialize_all = "lowercase")]
pub enum ProcessState {
#[default]
Pending,
Running,
Paused,
Stopping,
Exited,
Crashed,
Restarting,
}
impl ProcessState {
pub fn is_active(self) -> bool {
matches!(
self,
Self::Running | Self::Paused | Self::Stopping | Self::Restarting
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn defaults_to_pending() {
assert_eq!(ProcessState::default(), ProcessState::Pending);
}
#[test]
fn active_while_a_child_is_live_or_transitioning() {
assert!(ProcessState::Running.is_active());
assert!(ProcessState::Paused.is_active());
assert!(ProcessState::Stopping.is_active());
assert!(ProcessState::Restarting.is_active());
assert!(!ProcessState::Pending.is_active());
assert!(!ProcessState::Exited.is_active());
assert!(!ProcessState::Crashed.is_active());
}
}