#[allow(missing_docs)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum AgentName
{
MicrosoftInternetExplorer,
MicrosoftEdge,
MozillaFirefox,
GoogleChrome,
AppleSafari,
Opera,
AppleSafariIOs,
OperaMini,
GoogleAndroidBrowserAndWebComponent,
Blackberry,
OperaMobile,
GoogleChromeAndroid,
MozillaFirefoxAndroid,
MicrosoftInternetExplorerMobile,
UcBrowserAndroid,
SamsungBrowserAndroid,
QqBrowserAndroid,
BaiduBrowserAndroid,
#[doc(hidden)] __Nonexhaustive,
Unknown(String),
}
impl Default for AgentName
{
#[inline(always)]
fn default() -> Self
{
AgentName::GoogleChrome
}
}
impl<'de> Deserialize<'de> for AgentName
{
#[inline(always)]
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
{
struct AgentNameVisitor;
impl<'de> Visitor<'de> for AgentNameVisitor
{
type Value = AgentName;
#[inline(always)]
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result
{
formatter.write_str("an era name starting with 'e' followed by a signed integer")
}
#[inline(always)]
fn visit_str<E: de::Error>(self, v: &str) -> Result<Self::Value, E>
{
use self::AgentName::*;
let result = match v
{
"ie" => MicrosoftInternetExplorer,
"edge" => MicrosoftEdge,
"firefox" => MozillaFirefox,
"chrome" => GoogleChrome,
"safari" => AppleSafari,
"opera" => Opera,
"ios_saf" => AppleSafariIOs,
"op_mini" => OperaMini,
"android" => GoogleAndroidBrowserAndWebComponent,
"bb" => Blackberry,
"op_mob" => OperaMobile,
"and_chr" => GoogleChromeAndroid,
"and_ff" => MozillaFirefoxAndroid,
"ie_mob" => MicrosoftInternetExplorerMobile,
"and_uc" => UcBrowserAndroid,
"samsung" => SamsungBrowserAndroid,
"and_qq" => QqBrowserAndroid,
"baidu" => BaiduBrowserAndroid,
_ => Unknown(v.to_owned()),
};
Ok(result)
}
#[inline(always)]
fn visit_string<E: de::Error>(self, v: String) -> Result<Self::Value, E>
{
use self::AgentName::*;
let result = match &v[..]
{
"ie" => MicrosoftInternetExplorer,
"edge" => MicrosoftEdge,
"firefox" => MozillaFirefox,
"chrome" => GoogleChrome,
"safari" => AppleSafari,
"opera" => Opera,
"ios_saf" => AppleSafariIOs,
"op_mini" => OperaMini,
"android" => GoogleAndroidBrowserAndWebComponent,
"bb" => Blackberry,
"op_mob" => OperaMobile,
"and_chr" => GoogleChromeAndroid,
"and_ff" => MozillaFirefoxAndroid,
"ie_mob" => MicrosoftInternetExplorerMobile,
"and_uc" => UcBrowserAndroid,
"samsung" => SamsungBrowserAndroid,
"and_qq" => QqBrowserAndroid,
"baidu" => BaiduBrowserAndroid,
_ => Unknown(v),
};
Ok(result)
}
}
deserializer.deserialize_str(AgentNameVisitor)
}
}
impl AgentName
{
#[inline(always)]
pub fn agent<'a>(&'a self, can_i_use: &'a CanIUse) -> Option<Agent<'a>>
{
can_i_use.agent(self)
}
}