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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// This file is part of caniuse-serde. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/caniuse-serde/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
// Copyright © 2017 The developers of caniuse-serde. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/caniuse-serde/master/COPYRIGHT.
/// An agent is effectively a browser. It is not a rendering engine, although it is closely related
#[derive(Debug, Clone)]
pub struct Agent<'a>
{
agent_name: &'a AgentName,
agent_detail: &'a AgentDetail,
}
impl<'a> Agent<'a>
{
/// Agent name
#[inline(always)]
pub fn agent_name(&self) -> &'a AgentName
{
self.agent_name
}
/// Agent browser name
#[inline(always)]
pub fn browser_name(&self) -> &str
{
&self.agent_detail.name
}
/// Agent detail abbreviated name, eg 'Chr.' for chrome
#[inline(always)]
pub fn abbreviated_name(&self) -> &str
{
&self.agent_detail.abbreviated_name
}
/// prefix to use for this particular version (lacks leading and trailing dash)
/// varies per version only for legacy Opera using the Presto rendering engine (from -webkit- to -o-)
#[inline(always)]
pub fn prefix(&self, version: &Version) -> &'a Prefix
{
match self.agent_detail.prefix_exceptions.get(version)
{
Some(prefix) => prefix,
None => &self.agent_detail.prefix,
}
}
/// Is this a desktop or mobile agent?
#[inline(always)]
pub fn agent_type(&self) -> AgentType
{
self.agent_detail.agent_type
}
/// Global usage; differs from `VersionDetail.global_usage()` **and** from `RegionalUsage::WorldWide`.
/// It is recommended to use the values in `RegionalUsage::WorldWide` for consistency.
#[inline(always)]
pub fn global_usage(&self, version: &Version) -> Option<UsagePercentage>
{
self.agent_detail.usage_global.get(version).map(|value| *value)
}
/// Details of every known version.
#[inline(always)]
pub fn version_details(&'a self) -> &'a BTreeMap<Version, VersionDetail>
{
&self.agent_detail.version_list
}
/// Current version as of `CanIUse.last_updated()`.
#[inline(always)]
pub fn current_version(&'a self) -> &'a Version
{
&self.agent_detail.current_version
}
/// Historic prefixes.
/// Only currently supplied for Opera Presto versions.
/// Duplicated in `version_details()`
#[inline(always)]
pub fn prefix_exceptions(&'a self) -> &'a BTreeMap<Version, Prefix>
{
&self.agent_detail.prefix_exceptions
}
/// Details of versions that are current or older
#[inline(always)]
pub fn version_details_for_current_and_older_versions(&'a self) -> Range<Version, VersionDetail>
{
use self::Bound::*;
self.version_details().range((Unbounded, Included(self.current_version())))
}
/// Details of version
#[inline(always)]
pub fn version_detail(&'a self, version: &Version) -> Option<&'a VersionDetail>
{
self.agent_detail.version_list.get(version)
}
}