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 | mod canonicalizer; |
19 | pub use canonicalizer::*; |
20 | use icu_locid::subtags::Language; |
21 | mod directionality; |
22 | pub use directionality::*; |
23 | mod expander; |
24 | pub use expander::*; |
25 | mod fallback; |
26 | pub use fallback::*; |
27 | |
28 | #[cfg (feature = "compiled_data" )] |
29 | #[derive (Debug)] |
30 | /// Baked data |
31 | /// |
32 | /// <div class="stab unstable"> |
33 | /// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, |
34 | /// including in SemVer minor releases. In particular, the `DataProvider` implementations are only |
35 | /// guaranteed to match with this version's `*_unstable` providers. Use with caution. |
36 | /// </div> |
37 | pub struct Baked; |
38 | |
39 | #[cfg (feature = "compiled_data" )] |
40 | const _: () = { |
41 | pub mod icu { |
42 | pub use crate as locid_transform; |
43 | pub use icu_locid as locid; |
44 | } |
45 | icu_locid_transform_data::make_provider!(Baked); |
46 | icu_locid_transform_data::impl_fallback_likelysubtags_v1!(Baked); |
47 | icu_locid_transform_data::impl_fallback_parents_v1!(Baked); |
48 | icu_locid_transform_data::impl_fallback_supplement_co_v1!(Baked); |
49 | icu_locid_transform_data::impl_locid_transform_aliases_v2!(Baked); |
50 | icu_locid_transform_data::impl_locid_transform_likelysubtags_ext_v1!(Baked); |
51 | icu_locid_transform_data::impl_locid_transform_likelysubtags_l_v1!(Baked); |
52 | icu_locid_transform_data::impl_locid_transform_likelysubtags_sr_v1!(Baked); |
53 | icu_locid_transform_data::impl_locid_transform_script_dir_v1!(Baked); |
54 | }; |
55 | |
56 | #[cfg (feature = "datagen" )] |
57 | use icu_provider::prelude::*; |
58 | |
59 | #[cfg (feature = "datagen" )] |
60 | /// The latest minimum set of keys required by this component. |
61 | pub const KEYS: &[DataKey] = &[ |
62 | AliasesV2Marker::KEY, |
63 | CollationFallbackSupplementV1Marker::KEY, |
64 | LikelySubtagsExtendedV1Marker::KEY, |
65 | LikelySubtagsForLanguageV1Marker::KEY, |
66 | LikelySubtagsForScriptRegionV1Marker::KEY, |
67 | LocaleFallbackLikelySubtagsV1Marker::KEY, |
68 | LocaleFallbackParentsV1Marker::KEY, |
69 | ScriptDirectionV1Marker::KEY, |
70 | ]; |
71 | |
72 | use alloc::borrow::Cow; |
73 | use tinystr::{TinyAsciiStr, UnvalidatedTinyAsciiStr}; |
74 | |
75 | // We use raw TinyAsciiStrs for map keys, as we then don't have to |
76 | // validate them as subtags on deserialization. Map lookup can be |
77 | // done even if they are not valid tags (an invalid key will just |
78 | // become inaccessible). |
79 | type UnvalidatedLanguage = UnvalidatedTinyAsciiStr<3>; |
80 | type UnvalidatedScript = UnvalidatedTinyAsciiStr<4>; |
81 | type UnvalidatedRegion = UnvalidatedTinyAsciiStr<3>; |
82 | type UnvalidatedVariant = UnvalidatedTinyAsciiStr<8>; |
83 | type UnvalidatedSubdivision = UnvalidatedTinyAsciiStr<7>; |
84 | type SemivalidatedSubdivision = TinyAsciiStr<7>; |
85 | |
86 | // LanguageIdentifier doesn't have an AsULE implementation, so we have |
87 | // to store strs and parse when needed. |
88 | type UnvalidatedLanguageIdentifier = str; |
89 | type UnvalidatedLanguageIdentifierPair = StrStrPairVarULE; |
90 | type UnvalidatedLanguageVariantsPair = LanguageStrStrPairVarULE; |
91 | |
92 | #[zerovec::make_varule (StrStrPairVarULE)] |
93 | #[zerovec::derive(Debug)] |
94 | #[derive (Clone, PartialEq, Eq, PartialOrd, Ord, Debug)] |
95 | #[cfg_attr ( |
96 | feature = "serde" , |
97 | derive(serde::Deserialize), |
98 | zerovec::derive(Deserialize) |
99 | )] |
100 | #[cfg_attr ( |
101 | feature = "datagen" , |
102 | derive(serde::Serialize, databake::Bake), |
103 | zerovec::derive(Serialize), |
104 | databake(path = icu_locid_transform::provider), |
105 | )] |
106 | /// A pair of strings with a EncodeAsVarULE implementation. |
107 | /// |
108 | /// <div class="stab unstable"> |
109 | /// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, |
110 | /// including in SemVer minor releases. While the serde representation of data structs is guaranteed |
111 | /// to be stable, their Rust representation might not be. Use with caution. |
112 | /// </div> |
113 | pub struct StrStrPair<'a>( |
114 | #[cfg_attr (feature = "serde" , serde(borrow))] pub Cow<'a, str>, |
115 | #[cfg_attr (feature = "serde" , serde(borrow))] pub Cow<'a, str>, |
116 | ); |
117 | |
118 | #[zerovec::make_varule (LanguageStrStrPairVarULE)] |
119 | #[zerovec::derive(Debug)] |
120 | #[derive (Clone, PartialEq, Eq, PartialOrd, Ord, Debug)] |
121 | #[cfg_attr ( |
122 | feature = "serde" , |
123 | derive(serde::Deserialize), |
124 | zerovec::derive(Deserialize) |
125 | )] |
126 | #[cfg_attr ( |
127 | feature = "datagen" , |
128 | derive(serde::Serialize, databake::Bake), |
129 | zerovec::derive(Serialize), |
130 | databake(path = icu_locid_transform::provider), |
131 | )] |
132 | /// A triplet of strings with a EncodeAsVarULE implementation. |
133 | pub struct LanguageStrStrPair<'a>( |
134 | pub Language, |
135 | #[cfg_attr (feature = "serde" , serde(borrow))] pub Cow<'a, str>, |
136 | #[cfg_attr (feature = "serde" , serde(borrow))] pub Cow<'a, str>, |
137 | ); |
138 | |