caniuse_serde/
AgentName.rs1#[allow(missing_docs)]
7#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
8pub enum AgentName
9{
10 MicrosoftInternetExplorer,
11 MicrosoftEdge,
12 MozillaFirefox,
13 GoogleChrome,
14 AppleSafari,
15 Opera,
16 AppleSafariIOs,
17 OperaMini,
18 GoogleAndroidBrowserAndWebComponent,
19 Blackberry,
20 OperaMobile,
21 GoogleChromeAndroid,
22 MozillaFirefoxAndroid,
23 MicrosoftInternetExplorerMobile,
24 UcBrowserAndroid,
25 SamsungBrowserAndroid,
26 QqBrowserAndroid,
27 BaiduBrowserAndroid,
28
29 #[doc(hidden)] __Nonexhaustive,
30
31 Unknown(String),
33}
34
35impl Default for AgentName
36{
37 #[inline(always)]
39 fn default() -> Self
40 {
41 AgentName::GoogleChrome
42 }
43}
44
45impl<'de> Deserialize<'de> for AgentName
46{
47 #[inline(always)]
49 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
50 {
51 struct AgentNameVisitor;
52
53 impl<'de> Visitor<'de> for AgentNameVisitor
54 {
55 type Value = AgentName;
56
57 #[inline(always)]
58 fn expecting(&self, formatter: &mut Formatter) -> fmt::Result
59 {
60 formatter.write_str("an era name starting with 'e' followed by a signed integer")
61 }
62
63 #[inline(always)]
64 fn visit_str<E: de::Error>(self, v: &str) -> Result<Self::Value, E>
65 {
66 use self::AgentName::*;
67
68 let result = match v
69 {
70 "ie" => MicrosoftInternetExplorer,
71 "edge" => MicrosoftEdge,
72 "firefox" => MozillaFirefox,
73 "chrome" => GoogleChrome,
74 "safari" => AppleSafari,
75 "opera" => Opera,
76 "ios_saf" => AppleSafariIOs,
77 "op_mini" => OperaMini,
78 "android" => GoogleAndroidBrowserAndWebComponent,
79 "bb" => Blackberry,
80 "op_mob" => OperaMobile,
81 "and_chr" => GoogleChromeAndroid,
82 "and_ff" => MozillaFirefoxAndroid,
83 "ie_mob" => MicrosoftInternetExplorerMobile,
84 "and_uc" => UcBrowserAndroid,
85 "samsung" => SamsungBrowserAndroid,
86 "and_qq" => QqBrowserAndroid,
87 "baidu" => BaiduBrowserAndroid,
88
89 _ => Unknown(v.to_owned()),
90 };
91 Ok(result)
92 }
93
94 #[inline(always)]
95 fn visit_string<E: de::Error>(self, v: String) -> Result<Self::Value, E>
96 {
97 use self::AgentName::*;
98
99 let result = match &v[..]
100 {
101 "ie" => MicrosoftInternetExplorer,
102 "edge" => MicrosoftEdge,
103 "firefox" => MozillaFirefox,
104 "chrome" => GoogleChrome,
105 "safari" => AppleSafari,
106 "opera" => Opera,
107 "ios_saf" => AppleSafariIOs,
108 "op_mini" => OperaMini,
109 "android" => GoogleAndroidBrowserAndWebComponent,
110 "bb" => Blackberry,
111 "op_mob" => OperaMobile,
112 "and_chr" => GoogleChromeAndroid,
113 "and_ff" => MozillaFirefoxAndroid,
114 "ie_mob" => MicrosoftInternetExplorerMobile,
115 "and_uc" => UcBrowserAndroid,
116 "samsung" => SamsungBrowserAndroid,
117 "and_qq" => QqBrowserAndroid,
118 "baidu" => BaiduBrowserAndroid,
119
120 _ => Unknown(v),
121 };
122 Ok(result)
123 }
124 }
125
126 deserializer.deserialize_str(AgentNameVisitor)
127 }
128}
129
130impl AgentName
131{
132 #[inline(always)]
135 pub fn agent<'a>(&'a self, can_i_use: &'a CanIUse) -> Option<Agent<'a>>
136 {
137 can_i_use.agent(self)
138 }
139}