icu_datetime/provider/pattern/item/
mod.rs

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
5mod generic;
6mod ule;
7
8use crate::provider::fields::{Field, FieldLength, FieldSymbol};
9pub use generic::GenericPatternItem;
10
11/// An element of a [`Pattern`](super::runtime::Pattern).
12///
13/// <div class="stab unstable">
14/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
15/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
16/// to be stable, their Rust representation might not be. Use with caution.
17/// </div>
18#[derive(Debug, PartialEq, Eq, Clone, Copy)]
19#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
20#[cfg_attr(feature = "datagen", databake(path = icu_datetime::provider::pattern::item))]
21#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
22#[allow(clippy::exhaustive_enums)] // this type is stable
23pub enum PatternItem {
24    /// A field, like "abbreviated months". Mostly follows UTS 35.
25    Field(Field),
26    /// A literal code point.
27    Literal(char),
28}
29
30impl From<(FieldSymbol, FieldLength)> for PatternItem {
31    fn from(input: (FieldSymbol, FieldLength)) -> Self {
32        Self::Field(Field {
33            symbol: input.0,
34            length: input.1,
35        })
36    }
37}
38
39impl From<char> for PatternItem {
40    fn from(input: char) -> Self {
41        Self::Literal(input)
42    }
43}