prima_tracing/config/
country.rs

1use std::{
2    fmt::{Display, Formatter},
3    str::FromStr,
4};
5
6/// All the possible countries in which the application can run.
7#[derive(PartialEq, Eq, Debug, Clone)]
8pub enum Country {
9    Common,
10    Es,
11    It,
12    Uk,
13}
14
15impl FromStr for Country {
16    type Err = CountryParseError;
17
18    fn from_str(s: &str) -> Result<Self, Self::Err> {
19        match s {
20            "common" => Ok(Self::Common),
21            "it" => Ok(Self::It),
22            "es" => Ok(Self::Es),
23            "uk" => Ok(Self::Uk),
24            _ => Err(CountryParseError(s.to_string())),
25        }
26    }
27}
28
29impl Display for Country {
30    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
31        let country = match self {
32            Self::Common => "common",
33            Self::Es => "es",
34            Self::It => "it",
35            Self::Uk => "uk",
36        };
37        f.write_str(country)
38    }
39}
40
41#[derive(Debug)]
42pub struct CountryParseError(String);
43
44impl Display for CountryParseError {
45    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
46        f.write_fmt(format_args!(
47            "{} is not a valid country string. Allowed strings are 'common', 'it', 'es' and 'uk'.",
48            &self.0
49        ))
50    }
51}