Debian Codegraph @

debian/rust-vendor/icu_locale_fallback/src/provider.rs

raw
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 #[cfg(feature = "compiled_data")]
19 #[derive(Debug)]
20 /// Baked data
21 ///
22 /// <div class="stab unstable">
23 /// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
24 /// including in SemVer minor releases. In particular, the `DataProvider` implementations are only
25 /// guaranteed to match with this version's `*_unstable` providers. Use with caution.
26 /// </div>
27 pub struct Baked;
28
29 #[cfg(feature = "compiled_data")]
30 #[allow(unused_imports)]
31 const _: () = {
32 use icu_locale_fallback_data::*;
33 pub mod icu {
34 pub mod locale {
35 pub use crate as fallback;
36 }
37 }
38 pub use crate as icu_locale_fallback;
39 make_provider!(Baked);
40 impl_locale_likely_subtags_language_v1!(Baked);
41 impl_locale_parents_v1!(Baked);
42 };
43
44 icu_provider::data_marker!(
45 /// Marker for data for likely subtags for languages.
46 LocaleLikelySubtagsLanguageV1,
47 "locale/likely/subtags/language/v1",
48 LikelySubtagsForLanguage<'static>,
49 is_singleton = true
50 );
51 icu_provider::data_marker!(
52 /// Marker for locale fallback parents data.
53 LocaleParentsV1,
54 "locale/parents/v1",
55 Parents<'static>,
56 is_singleton = true
57 );
58
59 #[cfg(feature = "datagen")]
60 /// The latest minimum set of markers required by this component.
61 pub const MARKERS: &[DataMarkerInfo] =
62 &[LocaleLikelySubtagsLanguageV1::INFO, LocaleParentsV1::INFO];
63
64 use icu_locale_core::subtags::{Language, Region, Script};
65 use icu_provider::prelude::*;
66 use potential_utf::PotentialUtf8;
67 use tinystr::UnvalidatedTinyAsciiStr;
68 use zerovec::ZeroMap;
69
70 type UnvalidatedLanguage = UnvalidatedTinyAsciiStr<3>;
71 type UnvalidatedScript = UnvalidatedTinyAsciiStr<4>;
72 type UnvalidatedRegion = UnvalidatedTinyAsciiStr<3>;
73
74 #[derive(Debug, PartialEq, Clone, yoke::Yokeable, zerofrom::ZeroFrom)]
75 #[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
76 #[cfg_attr(feature = "datagen", databake(path = icu_locale_fallback::provider))]
77 #[cfg_attr(feature = "serde", derive(serde::Deserialize))]
78 /// This likely subtags data is used for the minimize and maximize operations.
79 ///
80 /// Each field defines a mapping from an old identifier to a new identifier,
81 /// based upon the rules in
82 /// <https://www.unicode.org/reports/tr35/#Likely_Subtags>.
83 ///
84 /// The data is stored is broken down into smaller vectors based upon the rules
85 /// defined for the likely subtags maximize algorithm.
86 ///
87 /// For efficiency, only the relevant part of the [`icu_locale_core::LanguageIdentifier`] is stored
88 /// for searching and replacing. E.g., the `language_script` field is used to store
89 /// rules for [`icu_locale_core::LanguageIdentifier`]s that contain a language and a script, but not a
90 /// region.
91 ///
92 /// This struct contains mappings when the input contains a language subtag.
93 ///
94 /// <div class="stab unstable">
95 /// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
96 /// including in SemVer minor releases. While the serde representation of data structs is guaranteed
97 /// to be stable, their Rust representation might not be. Use with caution.
98 /// </div>
99 #[yoke(prove_covariance_manually)]
100 pub struct LikelySubtagsForLanguage<'data> {
101 /// Language and script.
102 #[cfg_attr(feature = "serde", serde(borrow))]
103 pub language_script: ZeroMap<'data, (UnvalidatedLanguage, UnvalidatedScript), Region>,
104 /// Language and region.
105 #[cfg_attr(feature = "serde", serde(borrow))]
106 pub language_region: ZeroMap<'data, (UnvalidatedLanguage, UnvalidatedRegion), Script>,
107 /// Just language.
108 #[cfg_attr(feature = "serde", serde(borrow))]
109 pub language: ZeroMap<'data, UnvalidatedLanguage, (Script, Region)>,
110 /// Undefined.
111 pub und: (Language, Script, Region),
112 }
113
114 icu_provider::data_struct!(
115 LikelySubtagsForLanguage<'_>,
116 #[cfg(feature = "datagen")]
117 );
118
119 /// Locale fallback rules derived from CLDR parent locales data.
120 #[derive(Default, Clone, PartialEq, Debug, yoke::Yokeable, zerofrom::ZeroFrom)]
121 #[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
122 #[cfg_attr(feature = "datagen", databake(path = icu_locale_fallback::provider))]
123 #[cfg_attr(feature = "serde", derive(serde::Deserialize))]
124 #[yoke(prove_covariance_manually)]
125 pub struct Parents<'data> {
126 /// Map from language identifier to language identifier, indicating that the language on the
127 /// left should inherit from the language on the right.
128 #[cfg_attr(feature = "serde", serde(borrow))]
129 pub parents: ZeroMap<'data, PotentialUtf8, (Language, Option<Script>, Option<Region>)>,
130 }
131
132 icu_provider::data_struct!(
133 Parents<'_>,
134 #[cfg(feature = "datagen")]
135 );