pub struct PluralOperands { /* private fields */ }Expand description
A full plural operands representation of a number. See CLDR Plural Rules for complete operands description.
Plural operands in compliance with CLDR Plural Rules.
See full operands description.
§Data Types
The following types can be converted to PluralOperands:
- Integers, signed and unsigned
 - Strings representing an arbitrary-precision decimal
 Decimal
This crate does not support selection from a floating-point number, because floats are not
capable of carrying trailing zeros, which are required for proper plural rule selection. For
example, in English, “1 star” has a different plural form than “1.0 stars”, but this
distinction cannot be represented using a float. Clients should use Decimal instead.
§Examples
From int
use icu::plurals::PluralOperands;
use icu::plurals::RawPluralOperands;
assert_eq!(
    PluralOperands::from(RawPluralOperands {
        i: 2,
        v: 0,
        w: 0,
        f: 0,
        t: 0,
        c: 0,
    }),
    PluralOperands::from(2_usize)
);From &str
use icu::plurals::PluralOperands;
use icu::plurals::RawPluralOperands;
assert_eq!(
    Ok(PluralOperands::from(RawPluralOperands {
        i: 123,
        v: 2,
        w: 2,
        f: 45,
        t: 45,
        c: 0,
    })),
    "123.45".parse()
);From Decimal
use fixed_decimal::Decimal;
use icu::plurals::PluralOperands;
use icu::plurals::RawPluralOperands;
assert_eq!(
    PluralOperands::from(RawPluralOperands {
        i: 123,
        v: 2,
        w: 2,
        f: 45,
        t: 45,
        c: 0,
    }),
    (&{
        let mut decimal = Decimal::from(12345);
        decimal.multiply_pow10(-2);
        decimal
    })
        .into()
);Trait Implementations§
Source§impl Clone for PluralOperands
 
impl Clone for PluralOperands
Source§fn clone(&self) -> PluralOperands
 
fn clone(&self) -> PluralOperands
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PluralOperands
 
impl Debug for PluralOperands
Source§impl Default for PluralOperands
 
impl Default for PluralOperands
Source§fn default() -> PluralOperands
 
fn default() -> PluralOperands
Source§impl From<&CompactDecimal> for PluralOperands
 
impl From<&CompactDecimal> for PluralOperands
Source§fn from(compact: &CompactDecimal) -> Self
 
fn from(compact: &CompactDecimal) -> Self
Converts a fixed_decimal::CompactDecimal to PluralOperands. Retains at most 18
digits each from the integer and fraction parts.
§Examples
use fixed_decimal::CompactDecimal;
use fixed_decimal::Decimal;
use icu::locale::locale;
use icu::plurals::PluralCategory;
use icu::plurals::PluralOperands;
use icu::plurals::PluralRules;
use icu::plurals::RawPluralOperands;
let fixed_decimal = "1000000.20".parse::<Decimal>().unwrap();
let compact_decimal = "1.00000020c6".parse::<CompactDecimal>().unwrap();
assert_eq!(
    PluralOperands::from(RawPluralOperands {
        i: 1000000,
        v: 2,
        w: 1,
        f: 20,
        t: 2,
        c: 0,
    }),
    PluralOperands::from(&fixed_decimal)
);
assert_eq!(
    PluralOperands::from(RawPluralOperands {
        i: 1000000,
        v: 2,
        w: 1,
        f: 20,
        t: 2,
        c: 6,
    }),
    PluralOperands::from(&compact_decimal)
);
let rules = PluralRules::try_new_cardinal(locale!("fr").into()).unwrap();
assert_eq!(rules.category_for(&fixed_decimal), PluralCategory::Other);
assert_eq!(rules.category_for(&compact_decimal), PluralCategory::Many);Source§impl From<&Signed<UnsignedDecimal>> for PluralOperands
 
impl From<&Signed<UnsignedDecimal>> for PluralOperands
Source§fn from(dec: &Decimal) -> Self
 
fn from(dec: &Decimal) -> Self
Converts a fixed_decimal::Decimal to PluralOperands. Retains at most 18
digits each from the integer and fraction parts.
Source§impl From<i128> for PluralOperands
 
impl From<i128> for PluralOperands
Source§impl From<i16> for PluralOperands
 
impl From<i16> for PluralOperands
Source§impl From<i32> for PluralOperands
 
impl From<i32> for PluralOperands
Source§impl From<i64> for PluralOperands
 
impl From<i64> for PluralOperands
Source§impl From<i8> for PluralOperands
 
impl From<i8> for PluralOperands
Source§impl From<isize> for PluralOperands
 
impl From<isize> for PluralOperands
Source§impl From<u128> for PluralOperands
 
impl From<u128> for PluralOperands
Source§impl From<u16> for PluralOperands
 
impl From<u16> for PluralOperands
Source§impl From<u32> for PluralOperands
 
impl From<u32> for PluralOperands
Source§impl From<u64> for PluralOperands
 
impl From<u64> for PluralOperands
Source§impl From<u8> for PluralOperands
 
impl From<u8> for PluralOperands
Source§impl From<usize> for PluralOperands
 
impl From<usize> for PluralOperands
Source§impl PartialEq for PluralOperands
 
impl PartialEq for PluralOperands
impl Copy for PluralOperands
impl StructuralPartialEq for PluralOperands
Auto Trait Implementations§
impl Freeze for PluralOperands
impl RefUnwindSafe for PluralOperands
impl Send for PluralOperands
impl Sync for PluralOperands
impl Unpin for PluralOperands
impl UnwindSafe for PluralOperands
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more