1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10pub enum SpotStatus {
11 Normal = 0,
13 Excess = 1,
15 Anomaly = 2,
17}
18
19impl From<i32> for SpotStatus {
20 fn from(code: i32) -> Self {
21 match code {
22 0 => SpotStatus::Normal,
23 1 => SpotStatus::Excess,
24 2 => SpotStatus::Anomaly,
25 _ => SpotStatus::Normal, }
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33
34 #[test]
35 fn test_spot_status_values() {
36 assert_eq!(SpotStatus::Normal as i32, 0);
38 assert_eq!(SpotStatus::Excess as i32, 1);
39 assert_eq!(SpotStatus::Anomaly as i32, 2);
40 }
41
42 #[test]
43 fn test_spot_status_from_i32() {
44 assert_eq!(SpotStatus::from(0), SpotStatus::Normal);
46 assert_eq!(SpotStatus::from(1), SpotStatus::Excess);
47 assert_eq!(SpotStatus::from(2), SpotStatus::Anomaly);
48
49 assert_eq!(SpotStatus::from(-1), SpotStatus::Normal);
51 assert_eq!(SpotStatus::from(99), SpotStatus::Normal);
52 }
53}