Coverage Report

Created: 2025-07-12 07:16

/rust/registry/src/index.crates.io-6f17d22bba15001f/icu_timezone-1.5.0/src/provider.rs
Line
Count
Source (jump to first uncovered line)
1
// This file is part of ICU4X. For terms of use, please see the file
2
// called LICENSE at the top level of the ICU4X source tree
3
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5
// Provider structs must be stable
6
#![allow(clippy::exhaustive_structs, clippy::exhaustive_enums)]
7
8
//! 🚧 \[Unstable\] Data provider struct definitions for this ICU4X component.
9
//!
10
//! <div class="stab unstable">
11
//! 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
12
//! including in SemVer minor releases. While the serde representation of data structs is guaranteed
13
//! to be stable, their Rust representation might not be. Use with caution.
14
//! </div>
15
//!
16
//! Read more about data providers: [`icu_provider`]
17
18
use core::ops::Deref;
19
use core::str::FromStr;
20
use icu_provider::prelude::*;
21
use tinystr::TinyAsciiStr;
22
use zerovec::ule::{AsULE, ULE};
23
use zerovec::{ZeroMap2d, ZeroSlice, ZeroVec};
24
25
pub mod names;
26
27
#[cfg(feature = "compiled_data")]
28
#[derive(Debug)]
29
/// Baked data
30
///
31
/// <div class="stab unstable">
32
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
33
/// including in SemVer minor releases. In particular, the `DataProvider` implementations are only
34
/// guaranteed to match with this version's `*_unstable` providers. Use with caution.
35
/// </div>
36
pub struct Baked;
37
38
#[cfg(feature = "compiled_data")]
39
const _: () = {
40
    pub mod icu {
41
        pub use crate as timezone;
42
    }
43
    icu_timezone_data::make_provider!(Baked);
44
    icu_timezone_data::impl_time_zone_bcp47_to_iana_v1!(Baked);
45
    icu_timezone_data::impl_time_zone_iana_to_bcp47_v1!(Baked);
46
    icu_timezone_data::impl_time_zone_iana_to_bcp47_v2!(Baked);
47
    icu_timezone_data::impl_time_zone_metazone_period_v1!(Baked);
48
};
49
50
#[cfg(feature = "datagen")]
51
/// The latest minimum set of keys required by this component.
52
pub const KEYS: &[DataKey] = &[
53
    MetazonePeriodV1Marker::KEY,
54
    names::Bcp47ToIanaMapV1Marker::KEY,
55
    names::IanaToBcp47MapV1Marker::KEY,
56
    names::IanaToBcp47MapV2Marker::KEY,
57
];
58
59
/// TimeZone ID in BCP47 format
60
///
61
/// <div class="stab unstable">
62
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
63
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
64
/// to be stable, their Rust representation might not be. Use with caution.
65
/// </div>
66
#[repr(transparent)]
67
0
#[derive(Debug, Clone, Copy, Eq, Ord, PartialEq, PartialOrd, yoke::Yokeable, ULE, Hash)]
Unexecuted instantiation: <icu_timezone::provider::TimeZoneBcp47Id as yoke::yokeable::Yokeable>::transform
Unexecuted instantiation: <icu_timezone::provider::TimeZoneBcp47Id as yoke::yokeable::Yokeable>::transform_owned
Unexecuted instantiation: <icu_timezone::provider::TimeZoneBcp47Id as yoke::yokeable::Yokeable>::make
Unexecuted instantiation: <icu_timezone::provider::TimeZoneBcp47Id as yoke::yokeable::Yokeable>::transform_mut::<_>
68
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake), databake(path = icu_timezone::provider))]
69
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
70
pub struct TimeZoneBcp47Id(pub TinyAsciiStr<8>);
71
72
impl FromStr for TimeZoneBcp47Id {
73
    type Err = tinystr::TinyStrError;
74
0
    fn from_str(s: &str) -> Result<Self, Self::Err> {
75
0
        TinyAsciiStr::from_str(s).map(Into::into)
76
0
    }
77
}
78
79
impl From<TinyAsciiStr<8>> for TimeZoneBcp47Id {
80
0
    fn from(s: TinyAsciiStr<8>) -> Self {
81
0
        Self(s)
82
0
    }
83
}
84
85
impl From<TimeZoneBcp47Id> for TinyAsciiStr<8> {
86
0
    fn from(other: TimeZoneBcp47Id) -> Self {
87
0
        other.0
88
0
    }
89
}
90
91
impl Deref for TimeZoneBcp47Id {
92
    type Target = TinyAsciiStr<8>;
93
94
0
    fn deref(&self) -> &Self::Target {
95
0
        &self.0
96
0
    }
97
}
98
99
impl AsULE for TimeZoneBcp47Id {
100
    type ULE = Self;
101
102
    #[inline]
103
0
    fn to_unaligned(self) -> Self::ULE {
104
0
        self
105
0
    }
106
107
    #[inline]
108
0
    fn from_unaligned(unaligned: Self::ULE) -> Self {
109
0
        unaligned
110
0
    }
111
}
112
113
impl<'a> zerovec::maps::ZeroMapKV<'a> for TimeZoneBcp47Id {
114
    type Container = ZeroVec<'a, TimeZoneBcp47Id>;
115
    type Slice = ZeroSlice<TimeZoneBcp47Id>;
116
    type GetType = TimeZoneBcp47Id;
117
    type OwnedType = TimeZoneBcp47Id;
118
}
119
120
/// Metazone ID in a compact format
121
///
122
/// <div class="stab unstable">
123
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
124
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
125
/// to be stable, their Rust representation might not be. Use with caution.
126
/// </div>
127
#[repr(transparent)]
128
0
#[derive(Debug, Clone, Copy, Eq, Ord, PartialEq, PartialOrd, yoke::Yokeable, ULE, Hash)]
Unexecuted instantiation: <icu_timezone::provider::MetazoneId as yoke::yokeable::Yokeable>::transform
Unexecuted instantiation: <icu_timezone::provider::MetazoneId as yoke::yokeable::Yokeable>::transform_owned
Unexecuted instantiation: <icu_timezone::provider::MetazoneId as yoke::yokeable::Yokeable>::make
Unexecuted instantiation: <icu_timezone::provider::MetazoneId as yoke::yokeable::Yokeable>::transform_mut::<_>
129
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake), databake(path = icu_timezone::provider))]
130
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
131
pub struct MetazoneId(pub TinyAsciiStr<4>);
132
133
impl From<TinyAsciiStr<4>> for MetazoneId {
134
0
    fn from(s: TinyAsciiStr<4>) -> Self {
135
0
        Self(s)
136
0
    }
137
}
138
139
impl From<MetazoneId> for TinyAsciiStr<4> {
140
0
    fn from(other: MetazoneId) -> Self {
141
0
        other.0
142
0
    }
143
}
144
145
impl FromStr for MetazoneId {
146
    type Err = tinystr::TinyStrError;
147
0
    fn from_str(s: &str) -> Result<Self, Self::Err> {
148
0
        TinyAsciiStr::from_str(s).map(Into::into)
149
0
    }
150
}
151
152
impl AsULE for MetazoneId {
153
    type ULE = Self;
154
155
    #[inline]
156
0
    fn to_unaligned(self) -> Self::ULE {
157
0
        self
158
0
    }
159
160
    #[inline]
161
0
    fn from_unaligned(unaligned: Self::ULE) -> Self {
162
0
        unaligned
163
0
    }
Unexecuted instantiation: <icu_timezone::provider::MetazoneId as zerovec::ule::AsULE>::from_unaligned
Unexecuted instantiation: <icu_timezone::provider::MetazoneId as zerovec::ule::AsULE>::from_unaligned
164
}
165
166
impl<'a> zerovec::maps::ZeroMapKV<'a> for MetazoneId {
167
    type Container = ZeroVec<'a, MetazoneId>;
168
    type Slice = ZeroSlice<MetazoneId>;
169
    type GetType = MetazoneId;
170
    type OwnedType = MetazoneId;
171
}
172
173
/// An ICU4X mapping to the metazones at a given period.
174
/// See CLDR-JSON metaZones.json for more context.
175
///
176
/// <div class="stab unstable">
177
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
178
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
179
/// to be stable, their Rust representation might not be. Use with caution.
180
/// </div>
181
0
#[icu_provider::data_struct(marker(
182
0
    MetazonePeriodV1Marker,
183
0
    "time_zone/metazone_period@1",
184
0
    singleton
185
0
))]
Unexecuted instantiation: <icu_timezone::provider::MetazonePeriodV1 as yoke::yokeable::Yokeable>::transform
Unexecuted instantiation: <icu_timezone::provider::MetazonePeriodV1 as zerofrom::zero_from::ZeroFrom<icu_timezone::provider::MetazonePeriodV1>>::zero_from
Unexecuted instantiation: <icu_timezone::provider::MetazonePeriodV1 as yoke::yokeable::Yokeable>::transform_owned
Unexecuted instantiation: <icu_timezone::provider::MetazonePeriodV1 as yoke::yokeable::Yokeable>::transform_mut::<_>
Unexecuted instantiation: <icu_timezone::provider::MetazonePeriodV1 as yoke::yokeable::Yokeable>::make
Unexecuted instantiation: <icu_timezone::provider::MetazonePeriodV1 as yoke::yokeable::Yokeable>::make
186
#[derive(PartialEq, Debug, Clone, Default)]
187
#[cfg_attr(
188
    feature = "datagen",
189
    derive(serde::Serialize, databake::Bake),
190
    databake(path = icu_timezone::provider),
191
)]
192
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
193
#[yoke(prove_covariance_manually)]
194
pub struct MetazonePeriodV1<'data>(
195
    /// The default mapping between period and metazone id. The second level key is a wall-clock time represented as the number of minutes since the local unix epoch. It represents when the metazone started to be used.
196
    #[cfg_attr(feature = "serde", serde(borrow))]
197
    pub ZeroMap2d<'data, TimeZoneBcp47Id, i32, Option<MetazoneId>>,
198
);