Debian Codegraph @

debian/rust-vendor/icu_plurals/benches/fixtures/mod.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 use icu_locale_core::LanguageIdentifier;
6 use icu_plurals::PluralCategory;
7
8 use serde::Deserialize;
9
10 #[derive(Deserialize)]
11 #[allow(dead_code)]
12 pub struct NumbersFixture {
13 pub isize: Vec<i64>,
14 pub usize: Vec<u64>,
15 pub string: Vec<String>,
16 pub string_samples: Vec<String>,
17 pub fixed_decimals: Vec<FromFixedDecimals>,
18 }
19
20 #[derive(Debug, Deserialize)]
21 #[allow(dead_code)]
22 pub struct PluralsFixture {
23 pub langs: Vec<LanguageIdentifier>,
24 }
25
26 /// Describes a number to construct from plural operands, as `value * 10^(exponent)`. Construction
27 /// from value and exponent is because sometimes we want to preserve trailing zeros.
28 #[derive(Deserialize)]
29 #[allow(dead_code)]
30 pub struct FromFixedDecimals {
31 pub value: i64,
32 pub exponent: i16,
33 }
34
35 #[derive(Debug, Deserialize)]
36 pub struct LocalePluralRulesFixture {
37 #[serde(rename = "pluralRule-count-zero")]
38 pub zero: Option<String>,
39 #[serde(rename = "pluralRule-count-one")]
40 pub one: Option<String>,
41 #[serde(rename = "pluralRule-count-two")]
42 pub two: Option<String>,
43 #[serde(rename = "pluralRule-count-few")]
44 pub few: Option<String>,
45 #[serde(rename = "pluralRule-count-many")]
46 pub many: Option<String>,
47 }
48
49 impl LocalePluralRulesFixture {
50 #[allow(dead_code)]
51 pub fn get(&self, category: PluralCategory) -> Option<&String> {
52 match category {
53 PluralCategory::Zero => self.zero.as_ref(),
54 PluralCategory::One => self.one.as_ref(),
55 PluralCategory::Two => self.two.as_ref(),
56 PluralCategory::Few => self.few.as_ref(),
57 PluralCategory::Many => self.many.as_ref(),
58 PluralCategory::Other => None,
59 }
60 }
61 }