pub struct PluralRules { /* private fields */ }
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§
Source§impl PluralRules
impl PluralRules
Sourcepub fn create<L: Into<LanguageIdentifier>>(
langid: L,
prt: PluralRuleType,
) -> Result<Self, &'static str>
pub fn create<L: Into<LanguageIdentifier>>( langid: L, prt: PluralRuleType, ) -> Result<Self, &'static str>
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());
Sourcepub fn select<N: TryInto<PluralOperands>>(
&self,
number: N,
) -> Result<PluralCategory, &'static str>
pub fn select<N: TryInto<PluralOperands>>( &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
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));
Sourcepub fn get_locales(prt: PluralRuleType) -> Vec<LanguageIdentifier>
pub fn get_locales(prt: PluralRuleType) -> Vec<LanguageIdentifier>
Returns a list of the available locales.
§Examples
use intl_pluralrules::{PluralRules, PluralRuleType};
assert_eq!(
PluralRules::get_locales(PluralRuleType::CARDINAL).is_empty(),
false
);
Sourcepub fn get_locale(&self) -> &LanguageIdentifier
pub fn get_locale(&self) -> &LanguageIdentifier
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§
Source§impl Clone for PluralRules
impl Clone for PluralRules
Source§fn clone(&self) -> PluralRules
fn clone(&self) -> PluralRules
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for PluralRules
impl RefUnwindSafe for PluralRules
impl Send for PluralRules
impl Sync for PluralRules
impl Unpin for PluralRules
impl UnwindSafe for PluralRules
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more