Struct icu_plurals::PluralOperands
source · 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
FixedDecimal
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 FixedDecimal
instead.
Examples
From int
use icu::plurals::PluralOperands;
use icu_plurals::rules::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::rules::RawPluralOperands;
assert_eq!(
Ok(PluralOperands::from(RawPluralOperands {
i: 123,
v: 2,
w: 2,
f: 45,
t: 45,
c: 0,
})),
"123.45".parse()
);
From FixedDecimal
use fixed_decimal::FixedDecimal;
use icu::plurals::PluralOperands;
use icu_plurals::rules::RawPluralOperands;
assert_eq!(
PluralOperands::from(RawPluralOperands {
i: 123,
v: 2,
w: 2,
f: 45,
t: 45,
c: 0,
}),
(&FixedDecimal::from(12345).multiplied_pow10(-2)).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<&FixedDecimal> for PluralOperands
impl From<&FixedDecimal> for PluralOperands
source§fn from(dec: &FixedDecimal) -> Self
fn from(dec: &FixedDecimal) -> Self
Converts a fixed_decimal::FixedDecimal
to PluralOperands
. Retains at most 18
digits each from the integer and fraction parts.
source§impl From<PluralOperands> for RawPluralOperands
impl From<PluralOperands> for RawPluralOperands
source§fn from(po: PluralOperands) -> RawPluralOperands
fn from(po: PluralOperands) -> RawPluralOperands
source§impl From<RawPluralOperands> for PluralOperands
impl From<RawPluralOperands> for PluralOperands
source§fn from(rpo: RawPluralOperands) -> PluralOperands
fn from(rpo: RawPluralOperands) -> PluralOperands
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 FromStr for PluralOperands
impl FromStr for PluralOperands
source§impl PartialEq for PluralOperands
impl PartialEq for PluralOperands
source§fn eq(&self, other: &PluralOperands) -> bool
fn eq(&self, other: &PluralOperands) -> bool
self
and other
values to be equal, and is used
by ==
.