[][src]Struct intl_pluralrules::IntlPluralRules

pub struct IntlPluralRules { /* fields omitted */ }

The main structure for selecting plural rules.

Examples

use intl_pluralrules::{IntlPluralRules, PluralRuleType, PluralCategory};

let pr_naq = IntlPluralRules::create("naq", PluralRuleType::CARDINAL).unwrap();
assert_eq!(pr_naq.select(1), Ok(PluralCategory::ONE));
assert_eq!(pr_naq.select("2"), Ok(PluralCategory::TWO));
assert_eq!(pr_naq.select(5.0), Ok(PluralCategory::OTHER));

Methods

impl IntlPluralRules[src]

pub fn create(lang: &str, prt: PluralRuleType) -> Result<Self, &'static str>[src]

Returns an instance of IntlPluralRules.

Examples

use intl_pluralrules::{IntlPluralRules, PluralRuleType};

let pr_naq = IntlPluralRules::create("naq", PluralRuleType::CARDINAL);
assert_eq!(pr_naq.is_ok(), !pr_naq.is_err());

let pr_broken = IntlPluralRules::create("test", PluralRuleType::CARDINAL);
assert_eq!(pr_broken.is_err(), !pr_broken.is_ok());

pub fn select<N: IntoPluralOperands>(
    &self,
    number: N
) -> Result<PluralCategory, &'static str>
[src]

Returns a result of the plural category for the given input.

If the input is not numeric.

Examples

use intl_pluralrules::{IntlPluralRules, PluralRuleType, PluralCategory};

let pr_naq = IntlPluralRules::create("naq", PluralRuleType::CARDINAL).unwrap();
assert_eq!(pr_naq.select(1), Ok(PluralCategory::ONE));
assert_eq!(pr_naq.select(2), Ok(PluralCategory::TWO));
assert_eq!(pr_naq.select(5), Ok(PluralCategory::OTHER));

pub fn get_locales(prt: PluralRuleType) -> &'static [&'static str][src]

Returns a list of the available locales.

Examples

use intl_pluralrules::{IntlPluralRules, PluralRuleType};

assert_eq!(
    IntlPluralRules::get_locales(PluralRuleType::CARDINAL).is_empty(),
    false
);

pub fn get_locale(&self) -> &str[src]

Returns the locale name for this PluralRule instance.

Examples

use intl_pluralrules::{IntlPluralRules, PluralRuleType};

let pr_naq = IntlPluralRules::create("naq", PluralRuleType::CARDINAL).unwrap();
assert_eq!(pr_naq.get_locale(), "naq");

Trait Implementations

impl Clone for IntlPluralRules[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.