| 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 |
/// A list of options set by the developer to adjust the behavior of the [`PluralRules`](crate::PluralRules). |
| 6 |
/// |
| 7 |
/// # Examples |
| 8 |
/// ``` |
| 9 |
/// use icu::plurals::{PluralRuleType, PluralRulesOptions}; |
| 10 |
/// |
| 11 |
/// let options = |
| 12 |
/// PluralRulesOptions::default().with_type(PluralRuleType::Cardinal); |
| 13 |
/// ``` |
| 14 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 15 |
#[non_exhaustive] |
| 16 |
pub struct PluralRulesOptions { |
| 17 |
/// Plural rule type to use. |
| 18 |
/// |
| 19 |
/// Default is [`PluralRuleType::Cardinal`] |
| 20 |
pub rule_type: Option<PluralRuleType>, |
| 21 |
} |
| 22 |
|
| 23 |
impl Default for PluralRulesOptions { |
| 24 |
fn default() -> Self { |
| 25 |
Self::default() |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
impl PluralRulesOptions { |
| 30 |
/// Constructs a new [`PluralRulesOptions`] struct. |
| 31 |
pub const fn default() -> Self { |
| 32 |
Self { rule_type: None } |
| 33 |
} |
| 34 |
|
| 35 |
/// Auguments the struct with the set [`PluralRuleType`]. |
| 36 |
pub const fn with_type(mut self, rule_type: PluralRuleType) -> Self { |
| 37 |
self.rule_type = Some(rule_type); |
| 38 |
self |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
impl From<PluralRuleType> for PluralRulesOptions { |
| 43 |
fn from(value: PluralRuleType) -> Self { |
| 44 |
Self { |
| 45 |
rule_type: Some(value), |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/// A type of a plural rule which can be associated with the [`PluralRules`] struct. |
| 51 |
/// |
| 52 |
/// [`PluralRules`]: crate::PluralRules |
| 53 |
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Default)] |
| 54 |
#[non_exhaustive] |
| 55 |
pub enum PluralRuleType { |
| 56 |
/// Cardinal plural forms express quantities of units such as time, currency or distance, |
| 57 |
/// used in conjunction with a number expressed in decimal digits (i.e. "2", not "two"). |
| 58 |
/// |
| 59 |
/// For example, English has two forms for cardinals: |
| 60 |
/// |
| 61 |
/// * [`One`]: `1 day` |
| 62 |
/// * [`Other`]: `0 days`, `2 days`, `10 days`, `0.3 days` |
| 63 |
/// |
| 64 |
/// [`One`]: crate::PluralCategory::One |
| 65 |
/// [`Other`]: crate::PluralCategory::Other |
| 66 |
#[default] |
| 67 |
Cardinal, |
| 68 |
/// Ordinal plural forms denote the order of items in a set and are always integers. |
| 69 |
/// |
| 70 |
/// For example, English has four forms for ordinals: |
| 71 |
/// |
| 72 |
/// * [`One`]: `1st floor`, `21st floor`, `101st floor` |
| 73 |
/// * [`Two`]: `2nd floor`, `22nd floor`, `102nd floor` |
| 74 |
/// * [`Few`]: `3rd floor`, `23rd floor`, `103rd floor` |
| 75 |
/// * [`Other`]: `4th floor`, `11th floor`, `96th floor` |
| 76 |
/// |
| 77 |
/// [`One`]: crate::PluralCategory::One |
| 78 |
/// [`Two`]: crate::PluralCategory::Two |
| 79 |
/// [`Few`]: crate::PluralCategory::Few |
| 80 |
/// [`Other`]: crate::PluralCategory::Other |
| 81 |
Ordinal, |
| 82 |
} |