srdf/
lang.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use std::fmt::Display;

use serde_derive::{Deserialize, Serialize};

#[derive(Default, PartialEq, Eq, Hash, Debug, Serialize, Deserialize, Clone)]
pub struct Lang {
    lang: String,
}

impl Lang {
    pub fn new(str: &str) -> Lang {
        Lang {
            lang: str.to_lowercase().to_string(),
        }
    }

    pub fn value(&self) -> String {
        self.lang.clone()
    }
}

impl Display for Lang {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "@{}", self.lang)
    }
}