whoami/
language.rs
1use std::fmt::{self, Display, Formatter};
2
3#[non_exhaustive]
7#[repr(u32)]
8#[derive(Copy, Clone, Eq, PartialEq, Debug)]
9pub enum Country {
10 Any,
14 #[doc(hidden)]
16 Us,
17}
18
19impl Display for Country {
20 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
21 f.write_str(match self {
22 Self::Any => "**",
23 Self::Us => "US",
24 })
25 }
26}
27
28#[non_exhaustive]
36#[derive(Clone, Eq, PartialEq, Debug)]
37pub enum Language {
39 #[doc(hidden)]
40 __(Box<String>),
41 #[doc(hidden)]
43 En(Country),
44 #[doc(hidden)]
46 Es(Country),
47}
48
49impl Language {
50 pub fn country(&self) -> Country {
52 match self {
53 Self::__(_) => Country::Any,
54 Self::En(country) | Self::Es(country) => *country,
55 }
56 }
57}
58
59impl Display for Language {
60 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
61 match self {
62 Self::__(code) => f.write_str(code.as_str()),
63 Self::En(country) => {
64 if *country != Country::Any {
65 f.write_str("en/")?;
66 <Country as Display>::fmt(country, f)
67 } else {
68 f.write_str("en")
69 }
70 }
71 Self::Es(country) => {
72 if *country != Country::Any {
73 f.write_str("es/")?;
74 <Country as Display>::fmt(country, f)
75 } else {
76 f.write_str("es")
77 }
78 }
79 }
80 }
81}