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
18mod canonicalizer;
19pub use canonicalizer::*;
20mod directionality;
21pub use directionality::*;
22mod expander;
23pub use expander::*;
24mod fallback;
25pub use fallback::*;
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>
36pub struct Baked;
37
38#[cfg(feature = "compiled_data")]
39const _: () = {
40 pub mod icu {
41 pub use crate as locid_transform;
42 pub use icu_locid as locid;
43 }
44 icu_locid_transform_data::make_provider!(Baked);
45 icu_locid_transform_data::impl_fallback_likelysubtags_v1!(Baked);
46 icu_locid_transform_data::impl_fallback_parents_v1!(Baked);
47 icu_locid_transform_data::impl_fallback_supplement_co_v1!(Baked);
48 icu_locid_transform_data::impl_locid_transform_aliases_v1!(Baked);
49 icu_locid_transform_data::impl_locid_transform_likelysubtags_ext_v1!(Baked);
50 icu_locid_transform_data::impl_locid_transform_likelysubtags_l_v1!(Baked);
51 icu_locid_transform_data::impl_locid_transform_likelysubtags_sr_v1!(Baked);
52 icu_locid_transform_data::impl_locid_transform_script_dir_v1!(Baked);
53};
54
55use alloc::borrow::Cow;
56use tinystr::{TinyAsciiStr, UnvalidatedTinyAsciiStr};
57
58// We use raw TinyAsciiStrs for map keys, as we then don't have to
59// validate them as subtags on deserialization. Map lookup can be
60// done even if they are not valid tags (an invalid key will just
61// become inaccessible).
62type UnvalidatedLanguage = UnvalidatedTinyAsciiStr<3>;
63type UnvalidatedScript = UnvalidatedTinyAsciiStr<4>;
64type UnvalidatedRegion = UnvalidatedTinyAsciiStr<3>;
65type UnvalidatedVariant = UnvalidatedTinyAsciiStr<8>;
66type UnvalidatedSubdivision = UnvalidatedTinyAsciiStr<7>;
67type SemivalidatedSubdivision = TinyAsciiStr<7>;
68
69// LanguageIdentifier doesn't have an AsULE implementation, so we have
70// to store strs and parse when needed.
71type UnvalidatedLanguageIdentifier = str;
72type UnvalidatedLanguageIdentifierPair = StrStrPairVarULE;
73
74#[zerovec::make_varule(StrStrPairVarULE)]
75#[zerovec::derive(Debug)]
76#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
77#[cfg_attr(
78 feature = "serde",
79 derive(serde::Deserialize),
80 zerovec::derive(Deserialize)
81)]
82#[cfg_attr(
83 feature = "datagen",
84 derive(serde::Serialize, databake::Bake),
85 zerovec::derive(Serialize),
86 databake(path = icu_locid_transform::provider),
87)]
88/// A pair of strings with a EncodeAsVarULE implementation.
89///
90/// <div class="stab unstable">
91/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
92/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
93/// to be stable, their Rust representation might not be. Use with caution.
94/// </div>
95pub struct StrStrPair<'a>(
96 #[cfg_attr(feature = "serde", serde(borrow))] pub Cow<'a, str>,
97 #[cfg_attr(feature = "serde", serde(borrow))] pub Cow<'a, str>,
98);
99