Struct icu::plurals::PluralRulesWithRanges
source · pub struct PluralRulesWithRanges<R> { /* private fields */ }
Expand description
A PluralRules
that also has the ability to retrieve an appropriate Plural Category
for a
range.
✨ Enabled with the experimental
Cargo feature.
§Examples
use icu::locale::locale;
use icu::plurals::{PluralCategory, PluralOperands};
use icu::plurals::{PluralRuleType, PluralRulesWithRanges};
let ranges = PluralRulesWithRanges::try_new(
locale!("ar").into(),
PluralRuleType::Cardinal,
)
.expect("locale should be present");
let operands = PluralOperands::from(1_usize);
let operands2: PluralOperands =
"2.0".parse().expect("parsing to operands should succeed");
assert_eq!(
ranges.category_for_range(operands, operands2),
PluralCategory::Other
);
Implementations§
source§impl PluralRulesWithRanges<PluralRules>
impl PluralRulesWithRanges<PluralRules>
sourcepub fn try_new(
prefs: PluralRulesPreferences,
rule_type: PluralRuleType,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new( prefs: PluralRulesPreferences, rule_type: PluralRuleType, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
Constructs a new PluralRulesWithRanges
for a given locale using compiled data.
§Examples
use icu::locale::locale;
use icu::plurals::{PluralRuleType, PluralRulesWithRanges};
let _ = PluralRulesWithRanges::try_new(
locale!("en").into(),
PluralRuleType::Cardinal,
).expect("locale should be present");
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
prefs: PluralRulesPreferences,
rule_type: PluralRuleType,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), prefs: PluralRulesPreferences, rule_type: PluralRuleType, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
A version of [Self :: try_new
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
prefs: PluralRulesPreferences,
rule_type: PluralRuleType,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), prefs: PluralRulesPreferences, rule_type: PluralRuleType, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
A version of [Self :: try_new
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_unstable(
provider: &(impl DataProvider<PluralRangesV1Marker> + DataProvider<CardinalV1Marker> + DataProvider<OrdinalV1Marker> + ?Sized),
prefs: PluralRulesPreferences,
rule_type: PluralRuleType,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new_unstable( provider: &(impl DataProvider<PluralRangesV1Marker> + DataProvider<CardinalV1Marker> + DataProvider<OrdinalV1Marker> + ?Sized), prefs: PluralRulesPreferences, rule_type: PluralRuleType, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
A version of Self::try_new
that uses custom data provided by a DataProvider
.
sourcepub fn try_new_cardinal(
prefs: PluralRulesPreferences,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new_cardinal( prefs: PluralRulesPreferences, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
Constructs a new PluralRulesWithRanges
for a given locale for cardinal numbers using
compiled data.
See PluralRules::try_new_cardinal
for more information.
§Examples
use icu::locale::locale;
use icu::plurals::{PluralCategory, PluralRulesWithRanges};
let rules = PluralRulesWithRanges::try_new_cardinal(locale!("ru").into())
.expect("locale should be present");
assert_eq!(rules.category_for_range(0_usize, 2_usize), PluralCategory::Few);
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_cardinal_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
prefs: PluralRulesPreferences,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new_cardinal_with_any_provider( provider: &(impl AnyProvider + ?Sized), prefs: PluralRulesPreferences, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
A version of [Self :: try_new_cardinal
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_cardinal_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
prefs: PluralRulesPreferences,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new_cardinal_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), prefs: PluralRulesPreferences, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
A version of [Self :: try_new_cardinal
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_cardinal_unstable(
provider: &(impl DataProvider<CardinalV1Marker> + DataProvider<PluralRangesV1Marker> + ?Sized),
prefs: PluralRulesPreferences,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new_cardinal_unstable( provider: &(impl DataProvider<CardinalV1Marker> + DataProvider<PluralRangesV1Marker> + ?Sized), prefs: PluralRulesPreferences, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
A version of Self::try_new_cardinal
that uses custom data provided by a DataProvider
.
sourcepub fn try_new_ordinal(
prefs: PluralRulesPreferences,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new_ordinal( prefs: PluralRulesPreferences, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
Constructs a new PluralRulesWithRanges
for a given locale for ordinal numbers using
compiled data.
See PluralRules::try_new_ordinal
for more information.
§Examples
use icu::locale::locale;
use icu::plurals::{PluralCategory, PluralRulesWithRanges};
let rules = PluralRulesWithRanges::try_new_ordinal(
locale!("ru").into(),
)
.expect("locale should be present");
assert_eq!(rules.category_for_range(0_usize, 2_usize), PluralCategory::Other);
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_ordinal_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
prefs: PluralRulesPreferences,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new_ordinal_with_any_provider( provider: &(impl AnyProvider + ?Sized), prefs: PluralRulesPreferences, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
A version of [Self :: try_new_ordinal
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_ordinal_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
prefs: PluralRulesPreferences,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new_ordinal_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), prefs: PluralRulesPreferences, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
A version of [Self :: try_new_ordinal
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_ordinal_unstable(
provider: &(impl DataProvider<OrdinalV1Marker> + DataProvider<PluralRangesV1Marker> + ?Sized),
prefs: PluralRulesPreferences,
) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
pub fn try_new_ordinal_unstable( provider: &(impl DataProvider<OrdinalV1Marker> + DataProvider<PluralRangesV1Marker> + ?Sized), prefs: PluralRulesPreferences, ) -> Result<PluralRulesWithRanges<PluralRules>, DataError>
A version of Self::try_new_ordinal
that uses custom data provided by a DataProvider
.
source§impl<R> PluralRulesWithRanges<R>where
R: AsRef<PluralRules>,
impl<R> PluralRulesWithRanges<R>where
R: AsRef<PluralRules>,
sourcepub fn try_new_with_rules(
prefs: PluralRulesPreferences,
rules: R,
) -> Result<PluralRulesWithRanges<R>, DataError>
pub fn try_new_with_rules( prefs: PluralRulesPreferences, rules: R, ) -> Result<PluralRulesWithRanges<R>, DataError>
Constructs a new PluralRulesWithRanges
for a given locale from an existing
PluralRules
(either owned or as a reference) and compiled data.
§⚠️ Warning
The provided locale
MUST be the same as the locale provided to the constructor
of rules
. Otherwise, Self::category_for_range
will return incorrect results.
§Examples
use icu::locale::locale;
use icu::plurals::{PluralRuleType, PluralRulesWithRanges, PluralRules};
let rules = PluralRules::try_new(locale!("en").into(), PluralRuleType::Cardinal)
.expect("locale should be present");
let _ =
PluralRulesWithRanges::try_new_with_rules(locale!("en").into(), rules)
.expect("locale should be present");
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_with_rules_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
prefs: PluralRulesPreferences,
rules: R,
) -> Result<PluralRulesWithRanges<R>, DataError>
pub fn try_new_with_rules_with_any_provider( provider: &(impl AnyProvider + ?Sized), prefs: PluralRulesPreferences, rules: R, ) -> Result<PluralRulesWithRanges<R>, DataError>
A version of [Self :: try_new_with_rules
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_rules_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
prefs: PluralRulesPreferences,
rules: R,
) -> Result<PluralRulesWithRanges<R>, DataError>
pub fn try_new_with_rules_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), prefs: PluralRulesPreferences, rules: R, ) -> Result<PluralRulesWithRanges<R>, DataError>
A version of [Self :: try_new_with_rules
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_with_rules_unstable(
provider: &(impl DataProvider<PluralRangesV1Marker> + ?Sized),
prefs: PluralRulesPreferences,
rules: R,
) -> Result<PluralRulesWithRanges<R>, DataError>
pub fn try_new_with_rules_unstable( provider: &(impl DataProvider<PluralRangesV1Marker> + ?Sized), prefs: PluralRulesPreferences, rules: R, ) -> Result<PluralRulesWithRanges<R>, DataError>
A version of Self::try_new_with_rules
that uses custom data provided by a DataProvider
.
sourcepub fn rules(&self) -> &PluralRules
pub fn rules(&self) -> &PluralRules
Gets a reference to the inner PluralRules
.
§Examples
use icu::locale::locale;
use icu::plurals::{PluralCategory, PluralRulesWithRanges};
let ranges = PluralRulesWithRanges::try_new_cardinal(locale!("en").into())
.expect("locale should be present");
let rules = ranges.rules();
assert_eq!(rules.category_for(1u8), PluralCategory::One);
sourcepub fn category_for_range<S, E>(&self, start: S, end: E) -> PluralCategory
pub fn category_for_range<S, E>(&self, start: S, end: E) -> PluralCategory
Returns the Plural Category
appropriate for a range.
Note that the returned category is correct only if the range fulfills the following requirements:
- The start value is strictly less than the end value.
- Both values are positive.
§Examples
use icu::locale::locale;
use icu::plurals::{
PluralCategory, PluralOperands, PluralRuleType, PluralRulesWithRanges,
};
let ranges = PluralRulesWithRanges::try_new(
locale!("ro").into(),
PluralRuleType::Cardinal,
)
.expect("locale should be present");
let operands: PluralOperands =
"0.5".parse().expect("parsing to operands should succeed");
let operands2 = PluralOperands::from(1_usize);
assert_eq!(
ranges.category_for_range(operands, operands2),
PluralCategory::Few
);
sourcepub fn resolve_range(
&self,
start: PluralCategory,
end: PluralCategory,
) -> PluralCategory
pub fn resolve_range( &self, start: PluralCategory, end: PluralCategory, ) -> PluralCategory
Returns the Plural Category
appropriate for a range from the categories of its endpoints.
Note that the returned category is correct only if the original numeric range fulfills the following requirements:
- The start value is strictly less than the end value.
- Both values are positive.
§Examples
use icu::locale::locale;
use icu::plurals::{PluralCategory, PluralRuleType, PluralRulesWithRanges};
let ranges = PluralRulesWithRanges::try_new(
locale!("sl").into(),
PluralRuleType::Ordinal,
)
.expect("locale should be present");
assert_eq!(
ranges.resolve_range(PluralCategory::Other, PluralCategory::One),
PluralCategory::Few
);
Trait Implementations§
Auto Trait Implementations§
impl<R> Freeze for PluralRulesWithRanges<R>where
R: Freeze,
impl<R> RefUnwindSafe for PluralRulesWithRanges<R>where
R: RefUnwindSafe,
impl<R> Send for PluralRulesWithRanges<R>where
R: Send,
impl<R> Sync for PluralRulesWithRanges<R>where
R: Sync,
impl<R> Unpin for PluralRulesWithRanges<R>where
R: Unpin,
impl<R> UnwindSafe for PluralRulesWithRanges<R>where
R: UnwindSafe,
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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more