/rust/registry/src/index.crates.io-6f17d22bba15001f/icu_decimal-1.5.0/src/provider.rs
Line | Count | Source (jump to first uncovered line) |
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 | | //! 🚧 \[Unstable\] Data provider struct definitions for this ICU4X component. |
6 | | //! |
7 | | //! <div class="stab unstable"> |
8 | | //! 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, |
9 | | //! including in SemVer minor releases. While the serde representation of data structs is guaranteed |
10 | | //! to be stable, their Rust representation might not be. Use with caution. |
11 | | //! </div> |
12 | | //! |
13 | | //! Read more about data providers: [`icu_provider`] |
14 | | |
15 | | // Provider structs must be stable |
16 | | #![allow(clippy::exhaustive_structs)] |
17 | | #![allow(clippy::exhaustive_enums)] |
18 | | |
19 | | use alloc::borrow::Cow; |
20 | | use icu_provider::prelude::*; |
21 | | |
22 | | #[cfg(feature = "compiled_data")] |
23 | | #[derive(Debug)] |
24 | | /// Baked data |
25 | | /// |
26 | | /// <div class="stab unstable"> |
27 | | /// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, |
28 | | /// including in SemVer minor releases. In particular, the `DataProvider` implementations are only |
29 | | /// guaranteed to match with this version's `*_unstable` providers. Use with caution. |
30 | | /// </div> |
31 | | pub struct Baked; |
32 | | |
33 | | #[cfg(feature = "compiled_data")] |
34 | | const _: () = { |
35 | | pub mod icu { |
36 | | pub use crate as decimal; |
37 | | #[allow(unused_imports)] // baked data may or may not need this |
38 | | pub use icu_locid_transform as locid_transform; |
39 | | } |
40 | | icu_decimal_data::make_provider!(Baked); |
41 | | icu_decimal_data::impl_decimal_symbols_v1!(Baked); |
42 | | }; |
43 | | |
44 | | #[cfg(feature = "datagen")] |
45 | | /// The latest minimum set of keys required by this component. |
46 | | pub const KEYS: &[DataKey] = &[DecimalSymbolsV1Marker::KEY]; |
47 | | |
48 | | /// A collection of strings to affix to a decimal number. |
49 | | /// |
50 | | /// <div class="stab unstable"> |
51 | | /// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, |
52 | | /// including in SemVer minor releases. While the serde representation of data structs is guaranteed |
53 | | /// to be stable, their Rust representation might not be. Use with caution. |
54 | | /// </div> |
55 | 0 | #[derive(Debug, PartialEq, Clone, yoke::Yokeable, zerofrom::ZeroFrom)] Unexecuted instantiation: <icu_decimal::provider::AffixesV1 as yoke::yokeable::Yokeable>::transform Unexecuted instantiation: <icu_decimal::provider::AffixesV1 as yoke::yokeable::Yokeable>::transform_owned Unexecuted instantiation: <icu_decimal::provider::AffixesV1 as yoke::yokeable::Yokeable>::transform_mut::<_> |
56 | | #[cfg_attr( |
57 | | feature = "datagen", |
58 | | derive(serde::Serialize, databake::Bake), |
59 | | databake(path = icu_decimal::provider), |
60 | | )] |
61 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize))] |
62 | | pub struct AffixesV1<'data> { |
63 | | /// String to prepend before the decimal number. |
64 | | #[cfg_attr(feature = "serde", serde(borrow))] |
65 | | pub prefix: Cow<'data, str>, |
66 | | |
67 | | /// String to append after the decimal number. |
68 | | #[cfg_attr(feature = "serde", serde(borrow))] |
69 | | pub suffix: Cow<'data, str>, |
70 | | } |
71 | | |
72 | | /// A collection of settings expressing where to put grouping separators in a decimal number. |
73 | | /// For example, `1,000,000` has two grouping separators, positioned along every 3 digits. |
74 | | /// |
75 | | /// <div class="stab unstable"> |
76 | | /// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, |
77 | | /// including in SemVer minor releases. While the serde representation of data structs is guaranteed |
78 | | /// to be stable, their Rust representation might not be. Use with caution. |
79 | | /// </div> |
80 | 0 | #[derive(Debug, PartialEq, Clone, yoke::Yokeable, Copy, zerofrom::ZeroFrom)] Unexecuted instantiation: <icu_decimal::provider::GroupingSizesV1 as yoke::yokeable::Yokeable>::transform Unexecuted instantiation: <icu_decimal::provider::GroupingSizesV1 as yoke::yokeable::Yokeable>::transform_owned Unexecuted instantiation: <icu_decimal::provider::GroupingSizesV1 as yoke::yokeable::Yokeable>::make Unexecuted instantiation: <icu_decimal::provider::GroupingSizesV1 as yoke::yokeable::Yokeable>::transform_mut::<_> |
81 | | #[cfg_attr( |
82 | | feature = "datagen", |
83 | | derive(serde::Serialize, databake::Bake), |
84 | | databake(path = icu_decimal::provider), |
85 | | )] |
86 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize))] |
87 | | pub struct GroupingSizesV1 { |
88 | | /// The size of the first (lowest-magnitude) group. |
89 | | /// |
90 | | /// If 0, grouping separators will never be shown. |
91 | | pub primary: u8, |
92 | | |
93 | | /// The size of groups after the first group. |
94 | | /// |
95 | | /// If 0, defaults to be the same as `primary`. |
96 | | pub secondary: u8, |
97 | | |
98 | | /// The minimum number of digits required before the first group. For example, if `primary=3` |
99 | | /// and `min_grouping=2`, grouping separators will be present on 10,000 and above. |
100 | | pub min_grouping: u8, |
101 | | } |
102 | | |
103 | | /// Symbols and metadata required for formatting a [`FixedDecimal`](crate::FixedDecimal). |
104 | | /// |
105 | | /// <div class="stab unstable"> |
106 | | /// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, |
107 | | /// including in SemVer minor releases. While the serde representation of data structs is guaranteed |
108 | | /// to be stable, their Rust representation might not be. Use with caution. |
109 | | /// </div> |
110 | 0 | #[icu_provider::data_struct(marker( |
111 | 0 | DecimalSymbolsV1Marker, |
112 | 0 | "decimal/symbols@1", |
113 | 0 | extension_key = "nu" |
114 | 0 | ))] Unexecuted instantiation: <icu_decimal::provider::DecimalSymbolsV1 as yoke::yokeable::Yokeable>::transform Unexecuted instantiation: <icu_decimal::provider::DecimalSymbolsV1 as zerofrom::zero_from::ZeroFrom<icu_decimal::provider::DecimalSymbolsV1>>::zero_from Unexecuted instantiation: <icu_decimal::provider::DecimalSymbolsV1 as yoke::yokeable::Yokeable>::transform_owned Unexecuted instantiation: <icu_decimal::provider::DecimalSymbolsV1 as yoke::yokeable::Yokeable>::transform_mut::<_> Unexecuted instantiation: <icu_decimal::provider::DecimalSymbolsV1 as yoke::yokeable::Yokeable>::make Unexecuted instantiation: <icu_decimal::provider::DecimalSymbolsV1 as yoke::yokeable::Yokeable>::make |
115 | | #[derive(Debug, PartialEq, Clone)] |
116 | | #[cfg_attr( |
117 | | feature = "datagen", |
118 | | derive(serde::Serialize, databake::Bake), |
119 | | databake(path = icu_decimal::provider), |
120 | | )] |
121 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize))] |
122 | | pub struct DecimalSymbolsV1<'data> { |
123 | | /// Prefix and suffix to apply when a negative sign is needed. |
124 | | #[cfg_attr(feature = "serde", serde(borrow))] |
125 | | pub minus_sign_affixes: AffixesV1<'data>, |
126 | | |
127 | | /// Prefix and suffix to apply when a plus sign is needed. |
128 | | #[cfg_attr(feature = "serde", serde(borrow))] |
129 | | pub plus_sign_affixes: AffixesV1<'data>, |
130 | | |
131 | | /// Character used to separate the integer and fraction parts of the number. |
132 | | #[cfg_attr(feature = "serde", serde(borrow))] |
133 | | pub decimal_separator: Cow<'data, str>, |
134 | | |
135 | | /// Character used to separate groups in the integer part of the number. |
136 | | #[cfg_attr(feature = "serde", serde(borrow))] |
137 | | pub grouping_separator: Cow<'data, str>, |
138 | | |
139 | | /// Settings used to determine where to place groups in the integer part of the number. |
140 | | pub grouping_sizes: GroupingSizesV1, |
141 | | |
142 | | /// Digit characters for the current numbering system. In most systems, these digits are |
143 | | /// contiguous, but in some systems, such as *hanidec*, they are not contiguous. |
144 | | pub digits: [char; 10], |
145 | | } |
146 | | |
147 | | impl Default for DecimalSymbolsV1<'static> { |
148 | 0 | fn default() -> Self { |
149 | 0 | Self { |
150 | 0 | minus_sign_affixes: AffixesV1 { |
151 | 0 | prefix: Cow::Borrowed("-"), |
152 | 0 | suffix: Cow::Borrowed(""), |
153 | 0 | }, |
154 | 0 | plus_sign_affixes: AffixesV1 { |
155 | 0 | prefix: Cow::Borrowed("+"), |
156 | 0 | suffix: Cow::Borrowed(""), |
157 | 0 | }, |
158 | 0 | decimal_separator: ".".into(), |
159 | 0 | grouping_separator: ",".into(), |
160 | 0 | grouping_sizes: GroupingSizesV1 { |
161 | 0 | primary: 3, |
162 | 0 | secondary: 3, |
163 | 0 | min_grouping: 1, |
164 | 0 | }, |
165 | 0 | digits: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], |
166 | 0 | } |
167 | 0 | } |
168 | | } |