Struct intl_pluralrules::IntlPluralRules
source · pub struct IntlPluralRules { /* private fields */ }
Expand description
The main structure for selecting plural rules.
Examples
extern crate intl_pluralrules;
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));
Implementations
sourceimpl IntlPluralRules
impl IntlPluralRules
sourcepub fn create(lang: &str, prt: PluralRuleType) -> Result<Self, &'static str>
pub fn create(lang: &str, prt: PluralRuleType) -> Result<Self, &'static str>
Returns an instance of IntlPluralRules.
Examples
extern crate intl_pluralrules;
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());
sourcepub fn select<N: IntoPluralOperands>(
&self,
number: N
) -> Result<PluralCategory, &'static str>
pub fn select<N: IntoPluralOperands>(
&self,
number: N
) -> Result<PluralCategory, &'static str>
Returns a result of the plural category for the given input.
If the input is not numeric.
Examples
extern crate intl_pluralrules;
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));
sourcepub fn get_locales(prt: PluralRuleType) -> &'static [&'static str]
pub fn get_locales(prt: PluralRuleType) -> &'static [&'static str]
Returns a list of the available locales.
Examples
extern crate intl_pluralrules;
use intl_pluralrules::{IntlPluralRules, PluralRuleType};
assert_eq!(
IntlPluralRules::get_locales(PluralRuleType::CARDINAL).is_empty(),
false
);
sourcepub fn get_locale(&self) -> &str
pub fn get_locale(&self) -> &str
Returns the locale name for this PluralRule instance.
Examples
extern crate intl_pluralrules;
use intl_pluralrules::{IntlPluralRules, PluralRuleType};
let pr_naq = IntlPluralRules::create("naq", PluralRuleType::CARDINAL).unwrap();
assert_eq!(pr_naq.get_locale(), "naq");
Trait Implementations
sourceimpl Clone for IntlPluralRules
impl Clone for IntlPluralRules
sourcefn clone(&self) -> IntlPluralRules
fn clone(&self) -> IntlPluralRules
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations
impl RefUnwindSafe for IntlPluralRules
impl Send for IntlPluralRules
impl Sync for IntlPluralRules
impl Unpin for IntlPluralRules
impl UnwindSafe for IntlPluralRules
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more