use std::fmt;
#[derive(Debug)]
pub enum LangError {
Io {
locale: String,
cause: String,
},
Parse {
locale: String,
cause: String,
},
NotLoaded {
locale: String,
},
InvalidLocale {
locale: String,
},
}
impl fmt::Display for LangError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LangError::Io { locale, cause } => {
write!(f, "failed to read language file for '{locale}': {cause}")
}
LangError::Parse { locale, cause } => {
write!(f, "failed to parse language file for '{locale}': {cause}")
}
LangError::NotLoaded { locale } => {
write!(f, "locale '{locale}' has not been loaded")
}
LangError::InvalidLocale { locale } => {
write!(
f,
"locale '{locale}' is invalid; expected a single locale name without path separators"
)
}
}
}
}
impl std::error::Error for LangError {}