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
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
//! Data structs for calendar-specific symbols and patterns.
#[cfg(any(feature = "datagen", feature = "experimental"))]
mod skeletons;
mod symbols;
use crate::pattern;
use icu_provider::prelude::*;
#[cfg(any(feature = "datagen", feature = "experimental"))]
pub use skeletons::*;
pub use symbols::*;
size_test!(DateLengthsV1, date_lengths_v1_size, 224);
/// Pattern data for dates.
#[doc = date_lengths_v1_size!()]
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(
marker(BuddhistDateLengthsV1Marker, "datetime/buddhist/datelengths@1"),
marker(ChineseDateLengthsV1Marker, "datetime/chinese/datelengths@1"),
marker(CopticDateLengthsV1Marker, "datetime/coptic/datelengths@1"),
marker(DangiDateLengthsV1Marker, "datetime/dangi/datelengths@1"),
marker(EthiopianDateLengthsV1Marker, "datetime/ethiopic/datelengths@1"),
marker(GregorianDateLengthsV1Marker, "datetime/gregory/datelengths@1"),
marker(HebrewDateLengthsV1Marker, "datetime/hebrew/datelengths@1"),
marker(IndianDateLengthsV1Marker, "datetime/indian/datelengths@1"),
marker(IslamicDateLengthsV1Marker, "datetime/islamic/datelengths@1"),
marker(JapaneseDateLengthsV1Marker, "datetime/japanese/datelengths@1"),
marker(JapaneseExtendedDateLengthsV1Marker, "datetime/japanext/datelengths@1"),
marker(PersianDateLengthsV1Marker, "datetime/persian/datelengths@1"),
marker(RocDateLengthsV1Marker, "datetime/roc/datelengths@1")
)]
#[derive(Debug, PartialEq, Clone, Default)]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_datetime::provider::calendar),
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub struct DateLengthsV1<'data> {
/// Date pattern data, broken down by pattern length.
#[cfg_attr(feature = "serde", serde(borrow))]
pub date: patterns::LengthPatternsV1<'data>,
/// Patterns used to combine date and time length patterns into full date_time patterns.
#[cfg_attr(feature = "serde", serde(borrow))]
pub length_combinations: patterns::GenericLengthPatternsV1<'data>,
}
pub(crate) struct ErasedDateLengthsV1Marker;
impl DataMarker for ErasedDateLengthsV1Marker {
type Yokeable = DateLengthsV1<'static>;
}
size_test!(TimeLengthsV1, time_lengths_v1_size, 264);
/// Pattern data for times.
#[doc = time_lengths_v1_size!()]
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(marker(TimeLengthsV1Marker, "datetime/timelengths@1",))]
#[derive(Debug, PartialEq, Clone, Default)]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_datetime::provider::calendar),
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub struct TimeLengthsV1<'data> {
/// These patterns are common uses of time formatting, broken down by the length of the
/// pattern. Users can override the hour cycle with a preference, so there are two
/// pattern groups stored here. Note that the pattern will contain either h11 or h12.
#[cfg_attr(feature = "serde", serde(borrow))]
pub time_h11_h12: patterns::LengthPatternsV1<'data>,
/// These patterns are common uses of time formatting, broken down by the length of the
/// pattern. Users can override the hour cycle with a preference, so there are two
/// pattern groups stored here. Note that the pattern will contain either h23 or h24.
#[cfg_attr(feature = "serde", serde(borrow))]
pub time_h23_h24: patterns::LengthPatternsV1<'data>,
/// By default a locale will prefer one hour cycle type over another.
pub preferred_hour_cycle: pattern::CoarseHourCycle,
}
/// Data structs for date / time patterns that store data corresponding to pattern lengths
/// and/or plural forms.
pub mod patterns {
use super::*;
use crate::pattern::runtime::{self, GenericPattern, PatternPlurals};
/// Data struct for date/time patterns broken down by pattern length.
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[derive(Debug, PartialEq, Clone, Default, yoke::Yokeable, zerofrom::ZeroFrom)]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_datetime::provider::calendar::patterns),
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub struct LengthPatternsV1<'data> {
/// A full length date/time pattern.
#[cfg_attr(feature = "serde", serde(borrow))]
pub full: runtime::Pattern<'data>,
/// A long length date/time pattern.
#[cfg_attr(feature = "serde", serde(borrow))]
pub long: runtime::Pattern<'data>,
/// A medium length date/time pattern.
#[cfg_attr(feature = "serde", serde(borrow))]
pub medium: runtime::Pattern<'data>,
/// A short length date/time pattern.
#[cfg_attr(feature = "serde", serde(borrow))]
pub short: runtime::Pattern<'data>,
}
/// Data struct for generic date/time patterns, broken down by pattern length.
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[derive(Debug, PartialEq, Clone, Default, yoke::Yokeable, zerofrom::ZeroFrom)]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_datetime::provider::calendar::patterns),
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub struct GenericLengthPatternsV1<'data> {
/// A full length glue pattern of other formatted elements.
#[cfg_attr(feature = "serde", serde(borrow))]
pub full: GenericPattern<'data>,
/// A long length glue pattern of other formatted elements.
#[cfg_attr(feature = "serde", serde(borrow))]
pub long: GenericPattern<'data>,
/// A medium length glue pattern of other formatted elements.
#[cfg_attr(feature = "serde", serde(borrow))]
pub medium: GenericPattern<'data>,
/// A short length glue pattern of other formatted elements.
#[cfg_attr(feature = "serde", serde(borrow))]
pub short: GenericPattern<'data>,
}
#[icu_provider::data_struct]
#[derive(Debug, PartialEq, Clone, Default)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub(crate) struct PatternPluralsV1<'data>(
#[cfg_attr(feature = "serde", serde(borrow))] pub PatternPlurals<'data>,
);
impl<'data> From<PatternPlurals<'data>> for PatternPluralsV1<'data> {
fn from(pattern: PatternPlurals<'data>) -> Self {
Self(pattern)
}
}
/// Helper struct used to allow for projection of `DataPayload<DatePatternsV1>` to
/// `DataPayload<PatternPluralsV1>`.
pub(crate) struct PatternPluralsFromPatternsV1Marker;
impl DataMarker for PatternPluralsFromPatternsV1Marker {
type Yokeable = PatternPluralsV1<'static>;
}
/// A general purpose pattern representation. Used for date-time glue patterns.
///
/// Expresses the formatting positions of other formatted elements (ex: the order
/// and formatting of a date and a time within a date-time pattern).
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct]
#[derive(Debug, PartialEq, Clone, Default)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub struct GenericPatternV1<'data>(
#[cfg_attr(feature = "serde", serde(borrow))] pub GenericPattern<'data>,
);
/// Helper struct used to allow for projection of `DataPayload<DatePatternsV1>` to
/// `DataPayload<GenericLengthPatternsV1>`.
pub(crate) struct GenericPatternV1Marker;
impl DataMarker for GenericPatternV1Marker {
type Yokeable = GenericPatternV1<'static>;
}
impl<'data> From<GenericPattern<'data>> for GenericPatternV1<'data> {
fn from(pattern: GenericPattern<'data>) -> Self {
Self(pattern)
}
}
}