1#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
10pub enum AlertState {
11 #[default]
13 None = 0,
14 Locate = 1,
17}
18
19impl AlertState {
20 pub const fn code(self) -> u32 {
22 self as u32
23 }
24
25 pub const fn from_code(code: u32) -> Option<Self> {
27 match code {
28 0 => Some(Self::None),
29 1 => Some(Self::Locate),
30 _ => None,
31 }
32 }
33
34 pub const fn is_active(self) -> bool {
36 matches!(self, Self::Locate)
37 }
38}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn codes_round_trip_strictly() {
46 assert_eq!(AlertState::from_code(0), Some(AlertState::None));
47 assert_eq!(AlertState::from_code(1), Some(AlertState::Locate));
48 assert_eq!(AlertState::from_code(2), None);
49 assert_eq!(AlertState::None.code(), 0);
50 assert_eq!(AlertState::Locate.code(), 1);
51 }
52
53 #[test]
54 fn default_is_nominal() {
55 assert_eq!(AlertState::default(), AlertState::None);
56 assert!(!AlertState::default().is_active());
57 assert!(AlertState::Locate.is_active());
58 }
59}