Skip to main content

browserslist_data/caniuse/
region.rs

1use super::PooledStr;
2use crate::{
3    decode_browser_name,
4    utils::{BinMap, U32},
5};
6
7#[derive(Clone, Copy)]
8pub struct RegionData(u32, u32);
9
10// ```rust
11// static REGIONS: &[(PooledStr, RegionData)]; // region name and region data
12//
13// static REGIONS_BROWSERS: &[u8]; // browser name id
14// static REGIONS_VERSIONS: &[U32]; // version string
15// static REGIONS_USAGES: &[U32]; // browser usage (f32)
16// ```
17include!("../generated/caniuse-region-matching.rs");
18
19pub fn get_usage_by_region(region: &str) -> Option<RegionData> {
20    BinMap(REGIONS).get(region).copied()
21}
22
23impl RegionData {
24    pub fn iter(&self) -> impl Iterator<Item = (&'static str, &'static str, f32)> {
25        let range = (self.0 as usize)..(self.1 as usize);
26
27        REGIONS_BROWSERS[range.clone()]
28            .iter()
29            .zip(&REGIONS_VERSIONS[range.clone()])
30            .zip(&REGIONS_USAGES[range])
31            .map(|((browser, version), usage)| {
32                (
33                    decode_browser_name(*browser),
34                    PooledStr(version.get()).as_str(),
35                    f32::from_bits(usage.get()),
36                )
37            })
38    }
39}