use std::fmt::{self, Display, Formatter};
#[non_exhaustive]
#[repr(u32)]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Country {
Any,
#[doc(hidden)]
Us,
}
impl Display for Country {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Any => "**",
Self::Us => "US",
})
}
}
#[non_exhaustive]
#[derive(Clone, Eq, PartialEq, Debug)]
pub enum Language {
#[doc(hidden)]
__(Box<String>),
#[doc(hidden)]
En(Country),
#[doc(hidden)]
Es(Country),
}
impl Language {
pub fn country(&self) -> Country {
match self {
Self::__(_) => Country::Any,
Self::En(country) | Self::Es(country) => *country,
}
}
}
impl Display for Language {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::__(code) => f.write_str(code.as_str()),
Self::En(country) => {
if *country != Country::Any {
f.write_str("en/")?;
<Country as Display>::fmt(country, f)
} else {
f.write_str("en")
}
}
Self::Es(country) => {
if *country != Country::Any {
f.write_str("es/")?;
<Country as Display>::fmt(country, f)
} else {
f.write_str("es")
}
}
}
}
}