Struct intl_pluralrules::PluralRules[][src]

pub struct PluralRules { /* fields omitted */ }
Expand description

The main structure for selecting plural rules.

Examples

use intl_pluralrules::{PluralRules, PluralRuleType, PluralCategory};
use unic_langid::LanguageIdentifier;

let langid: LanguageIdentifier = "naq".parse().expect("Parsing failed.");
let pr_naq = PluralRules::create(langid, 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));

Implementations

Returns an instance of PluralRules.

Examples
use intl_pluralrules::{PluralRules, PluralRuleType, PluralCategory};
use unic_langid::LanguageIdentifier;

let langid: LanguageIdentifier = "naq".parse().expect("Parsing failed.");
let pr_naq = PluralRules::create(langid, PluralRuleType::CARDINAL);
assert_eq!(pr_naq.is_ok(), !pr_naq.is_err());

let langid: LanguageIdentifier = "xx".parse().expect("Parsing failed.");
let pr_broken = PluralRules::create(langid, PluralRuleType::CARDINAL);
assert_eq!(pr_broken.is_err(), !pr_broken.is_ok());

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

If the input is not numeric.

Examples
use intl_pluralrules::{PluralRules, PluralRuleType, PluralCategory};
use unic_langid::LanguageIdentifier;

let langid: LanguageIdentifier = "naq".parse().expect("Parsing failed.");
let pr_naq = PluralRules::create(langid, 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));

Returns a list of the available locales.

Examples
use intl_pluralrules::{PluralRules, PluralRuleType};

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

Returns the locale name for this PluralRule instance.

Examples
use intl_pluralrules::{PluralRules, PluralRuleType};
use unic_langid::LanguageIdentifier;

let langid: LanguageIdentifier = "naq".parse().expect("Parsing failed.");
let pr_naq = PluralRules::create(langid.clone(), PluralRuleType::CARDINAL).unwrap();
assert_eq!(pr_naq.get_locale(), &langid);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

Performs the conversion.

Performs the conversion.

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.