recipes/api/src/domain/misc_types.rs

39 lines
638 B
Rust

use std::str::FromStr;
#[derive(Debug, Default)]
pub struct Context {
pub lang: Lang,
}
#[cfg(test)]
impl Context {
pub fn eng() -> Self {
Self { lang: Lang::Eng }
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize)]
pub enum Lang {
Rus,
#[allow(dead_code)]
Eng,
}
impl Default for Lang {
fn default() -> Self {
Lang::Rus
}
}
impl FromStr for Lang {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match &s.to_lowercase()[..] {
"rus" => Ok(Lang::Rus),
"eng" => Ok(Lang::Eng),
_ => Err(()),
}
}
}