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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#[derive(Default, Debug, Clone)]
pub struct AgentNameAndVersionSet(HashSet<(AgentName, Version)>);
impl Deref for AgentNameAndVersionSet
{
type Target = HashSet<(AgentName, Version)>;
#[inline(always)]
fn deref(&self) -> &Self::Target
{
&self.0
}
}
impl AgentNameAndVersionSet
{
#[inline(always)]
pub fn support_for_a_feature<'a, F: FnMut(&Agent, &Version, &Support)>(&self, can_i_use: &'a CanIUse, feature_name: &'a FeatureName, mut support_user: F)
{
self.feature(can_i_use, feature_name, |agent, version, support|
{
if let Some(Some(ref support)) = support
{
support_user(agent, version, support)
}
})
}
#[inline(always)]
pub fn feature<'a, F: FnMut(&Agent, &Version, Option<Option<Support>>)>(&self, can_i_use: &'a CanIUse, feature_name: &'a FeatureName, mut feature_implementation_user: F)
{
if let Some(feature) = feature_name.feature(can_i_use)
{
for &(ref agent_name, ref version) in self.0.iter()
{
if let Some(agent) = agent_name.agent(can_i_use)
{
feature_implementation_user(&agent, version, feature.implementation(agent_name, version));
}
}
}
}
#[inline(always)]
pub fn new(values: HashSet<(AgentName, Version)>) -> Self
{
AgentNameAndVersionSet(values)
}
#[inline(always)]
pub fn a_sensible_set_of_choices_for_an_international_website_in_multiple_languages(can_i_use: &CanIUse, maximum_release_age_from_can_i_use_database_last_updated: Duration, minimum_usage_threshold: UsagePercentage, regional_usages: &[&RegionalUsage]) -> Self
{
let obsolete_browsers_still_in_use = Self::obsolete_browsers_still_in_use();
let browsers_which_underwent_a_major_change_of_rendering_engine = Self::browsers_which_underwent_a_major_change_of_rendering_engine();
let automatically_updated_browsers = Self::automatically_updated_browsers();
let long_term_releases_of_automatically_updated_browsers = Self::long_term_releases_of_automatically_updated_browsers();
let regionally_significant_occasionally_automatically_updated_browsers = Self::regionally_significant_occasionally_automatically_updated_browsers();
Self::sensible_choices(can_i_use, maximum_release_age_from_can_i_use_database_last_updated, minimum_usage_threshold, regional_usages, obsolete_browsers_still_in_use, browsers_which_underwent_a_major_change_of_rendering_engine, automatically_updated_browsers, long_term_releases_of_automatically_updated_browsers, regionally_significant_occasionally_automatically_updated_browsers)
}
pub fn sensible_choices(can_i_use: &CanIUse, maximum_release_age_from_can_i_use_database_last_updated: Duration, minimum_usage_threshold: UsagePercentage, regional_usages: &[&RegionalUsage], obsolete_browsers_still_in_use: Self, browsers_which_underwent_a_major_change_of_rendering_engine: Self, automatically_updated_browsers: HashSet<AgentName>, long_term_releases_of_automatically_updated_browsers: HashSet<AgentName>, regionally_significant_occasionally_automatically_updated_browsers: HashSet<AgentName>) -> Self
{
let mut result = Self::default();
for regional_usage in regional_usages.iter()
{
result.add_just_these_versions_by_usage_percentage(&obsolete_browsers_still_in_use, regional_usage, minimum_usage_threshold);
result.add_just_these_versions_by_usage_percentage(&browsers_which_underwent_a_major_change_of_rendering_engine, regional_usage, minimum_usage_threshold);
result.add_any_current_or_older_version_by_usage_percentage(®ionally_significant_occasionally_automatically_updated_browsers, regional_usage, minimum_usage_threshold, can_i_use);
}
let oldest_release_date = match can_i_use.last_updated().checked_sub_signed(maximum_release_age_from_can_i_use_database_last_updated)
{
Some(oldest_release_date) => oldest_release_date,
None => Utc.timestamp(0, 0),
};
result.add_any_current_or_older_version_by_age(&automatically_updated_browsers, oldest_release_date, can_i_use);
result.add_any_current_or_older_version_by_age(&long_term_releases_of_automatically_updated_browsers, oldest_release_date, can_i_use);
result
}
pub fn add_just_these_versions_by_usage_percentage(&mut self, obsolete_or_changed_rendering_engine: &Self, regional_usage: &RegionalUsage, minimum_usage_threshold: UsagePercentage)
{
for &(ref agent_name, ref version) in obsolete_or_changed_rendering_engine.0.iter()
{
if let Some(Some(&Some(actual_usage))) = regional_usage.usage_of_version(agent_name, version)
{
if actual_usage >= minimum_usage_threshold
{
self.0.insert((agent_name.clone(), version.clone()));
}
}
}
}
pub fn add_any_current_or_older_version_by_usage_percentage(&mut self, agent_names: &HashSet<AgentName>, regional_usage: &RegionalUsage, minimum_usage_threshold: UsagePercentage, can_i_use: &CanIUse)
{
for agent_name in agent_names.iter()
{
if let Some(agent) = agent_name.agent(can_i_use)
{
agent.version_details_for_current_and_older_versions().for_each(|(version, _version_detail)|
{
if let Some(Some(&Some(actual_usage))) = regional_usage.usage_of_version(agent_name, version)
{
if actual_usage >= minimum_usage_threshold
{
self.0.insert((agent_name.clone(), version.clone()));
}
}
})
}
}
}
pub fn add_any_current_or_older_version_by_age(&mut self, agent_names: &HashSet<AgentName>, oldest_release_date: DateTime<Utc>, can_i_use: &CanIUse)
{
for agent_name in agent_names.iter()
{
if let Some(agent) = agent_name.agent(can_i_use)
{
agent.version_details_for_current_and_older_versions().for_each(|(version, version_detail)|
{
if let Some(release_date) = version_detail.release_date()
{
if release_date >= oldest_release_date
{
self.0.insert((agent_name.clone(), version.clone()));
}
}
})
}
}
}
#[inline(always)]
pub fn obsolete_browsers_still_in_use() -> Self
{
use self::AgentName::*;
AgentNameAndVersionSet
(
hashset!
(
(MicrosoftInternetExplorer, Version::major(11)),
(Blackberry, Version::major(10)),
(MicrosoftInternetExplorerMobile, Version::major(11)),
)
)
}
#[inline(always)]
pub fn browsers_which_underwent_a_major_change_of_rendering_engine() -> Self
{
use self::AgentName::*;
AgentNameAndVersionSet
(
hashset!
(
(Opera, Version::major_minor(12, 1)),
(GoogleAndroidBrowserAndWebComponent, Version::major_minor_revision(4, 4, 4)),
(OperaMobile, Version::major_minor(12, 1)),
)
)
}
#[inline(always)]
pub fn automatically_updated_browsers() -> HashSet<AgentName>
{
use self::AgentName::*;
hashset!
(
MicrosoftEdge,
MozillaFirefox,
GoogleChrome,
AppleSafari,
Opera,
AppleSafariIOs,
GoogleAndroidBrowserAndWebComponent,
OperaMobile,
GoogleChromeAndroid,
MozillaFirefoxAndroid,
)
}
#[inline(always)]
pub fn long_term_releases_of_automatically_updated_browsers() -> HashSet<AgentName>
{
use self::AgentName::*;
hashset!
(
MozillaFirefox,
)
}
#[inline(always)]
pub fn regionally_significant_occasionally_automatically_updated_browsers() -> HashSet<AgentName>
{
use self::AgentName::*;
hashset!
(
UcBrowserAndroid,
SamsungBrowserAndroid,
QqBrowserAndroid,
BaiduBrowserAndroid,
)
}
}