| 1 | use std::fmt; |
| 2 | |
| 3 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 4 | pub enum State { |
| 5 | Alive, |
| 6 | Dead, |
| 7 | Unknown, |
| 8 | } |
| 9 | |
| 10 | impl State { |
| 11 | pub fn is_alive(&self) -> bool { |
| 12 | *self == Self::Alive |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | impl fmt::Display for State { |
| 17 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 18 | let s = match self { |
| 19 | Self::Alive => "alive", |
| 20 | Self::Dead => "dead", |
| 21 | Self::Unknown => "unknown", |
| 22 | }; |
| 23 | write!(f, "{}", s) |
| 24 | } |
| 25 | } |