use core::{fmt::Display, str::FromStr};
use rfham_core::error::CoreError;
use serde_with::{DeserializeFromStr, SerializeDisplay};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, DeserializeFromStr, SerializeDisplay)]
#[repr(u32)]
pub enum Region {
One = 1,
Two = 2,
Three = 3,
}
impl Display for Region {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match (self, f.alternate()) {
(Region::One, true) => "IARU/ITU Region 1",
(Region::One, false) => "1",
(Region::Two, true) => "IARU/ITU Region 2",
(Region::Two, false) => "2",
(Region::Three, true) => "IARU/ITU Region 3",
(Region::Three, false) => "3",
}
)
}
}
impl FromStr for Region {
type Err = CoreError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"1" | "one" => Ok(Self::One),
"2" | "two" => Ok(Self::Two),
"3" | "three" => Ok(Self::Three),
_ => Err(CoreError::InvalidValueFromStr(s.to_string(), "Region")),
}
}
}