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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Converts a [fixed_decimal::FixedDecimal] to PluralOperands. Retains at most 18 digits each from the integer and fraction parts.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.