39 lines
634 B
Rust
39 lines
634 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 {
|
|
"Rus" | "rus" => Ok(Lang::Rus),
|
|
"Eng" | "eng" => Ok(Lang::Eng),
|
|
_ => Err(()),
|
|
}
|
|
}
|
|
}
|