1use std::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum State {
7 Created,
9 Starting,
11 Running,
13 Stopping,
15 Stopped,
17 Failed,
19}
20
21impl fmt::Display for State {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 Self::Created => f.write_str("created"),
25 Self::Starting => f.write_str("starting"),
26 Self::Running => f.write_str("running"),
27 Self::Stopping => f.write_str("stopping"),
28 Self::Stopped => f.write_str("stopped"),
29 Self::Failed => f.write_str("failed"),
30 }
31 }
32}
33
34impl State {
35 pub(crate) const fn can_start(self) -> bool {
36 matches!(self, Self::Created | Self::Stopped | Self::Failed)
37 }
38
39 pub(crate) const fn should_stop(self) -> bool {
40 matches!(self, Self::Running)
41 }
42}
43
44#[cfg(test)]
45mod tests {
46 use super::State;
47
48 #[test]
49 fn display_matches_expected_values() {
50 assert_eq!(State::Created.to_string(), "created");
51 assert_eq!(State::Starting.to_string(), "starting");
52 assert_eq!(State::Running.to_string(), "running");
53 assert_eq!(State::Stopping.to_string(), "stopping");
54 assert_eq!(State::Stopped.to_string(), "stopped");
55 assert_eq!(State::Failed.to_string(), "failed");
56 }
57}