use crate::Region;
#[derive(Debug, Clone, PartialEq)]
pub enum Target {
National,
Postcode(String),
Region(Region),
}
impl From<String> for Target {
fn from(s: String) -> Self {
if s.trim().is_empty() | s.trim().eq_ignore_ascii_case("national") {
return Self::National;
}
if let Ok(region) = s.parse::<Region>() {
return Self::Region(region);
}
Self::Postcode(s)
}
}
impl std::fmt::Display for Target {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let target = match self {
Target::National => "National".to_string(),
Target::Postcode(postcode) => format!("postcode {postcode}"),
Target::Region(region) => region.to_string(),
};
write!(f, "{target}")
}
}