#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum SpotStatus {
Normal = 0,
Excess = 1,
Anomaly = 2,
}
impl From<i32> for SpotStatus {
fn from(code: i32) -> Self {
match code {
0 => SpotStatus::Normal,
1 => SpotStatus::Excess,
2 => SpotStatus::Anomaly,
_ => SpotStatus::Normal, }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_spot_status_values() {
assert_eq!(SpotStatus::Normal as i32, 0);
assert_eq!(SpotStatus::Excess as i32, 1);
assert_eq!(SpotStatus::Anomaly as i32, 2);
}
#[test]
fn test_spot_status_from_i32() {
assert_eq!(SpotStatus::from(0), SpotStatus::Normal);
assert_eq!(SpotStatus::from(1), SpotStatus::Excess);
assert_eq!(SpotStatus::from(2), SpotStatus::Anomaly);
assert_eq!(SpotStatus::from(-1), SpotStatus::Normal);
assert_eq!(SpotStatus::from(99), SpotStatus::Normal);
}
}