pub struct PluralElements<T>(/* private fields */);Expand description
A bag of values for different plural cases.
Implementations§
Source§impl<T> PluralElements<T>
 
impl<T> PluralElements<T>
Sourcepub fn new(other: T) -> Self
 
pub fn new(other: T) -> Self
Creates a new PluralElements with the given default value.
Sourcepub fn zero(&self) -> &T
 
pub fn zero(&self) -> &T
The value for PluralCategory::Zero
Sourcepub fn one(&self) -> &T
 
pub fn one(&self) -> &T
The value for PluralCategory::One
Sourcepub fn two(&self) -> &T
 
pub fn two(&self) -> &T
The value for PluralCategory::Two
Sourcepub fn few(&self) -> &T
 
pub fn few(&self) -> &T
The value for PluralCategory::Few
Sourcepub fn many(&self) -> &T
 
pub fn many(&self) -> &T
The value for PluralCategory::Many
Sourcepub fn other(&self) -> &T
 
pub fn other(&self) -> &T
The value for PluralCategory::Other
Sourcepub fn try_into_other(self) -> Option<T>
 
pub fn try_into_other(self) -> Option<T>
If the only variant is other, returns Some(other).
§Examples
use icu_plurals::PluralElements;
let mut only_other = PluralElements::new("abc").with_one_value(Some("abc"));
assert_eq!(only_other.try_into_other(), Some("abc"));
let mut multi = PluralElements::new("abc").with_one_value(Some("def"));
assert_eq!(multi.try_into_other(), None);Sourcepub fn explicit_zero(&self) -> Option<&T>
 
pub fn explicit_zero(&self) -> Option<&T>
The value used when the PluralOperands are exactly 0.
Sourcepub fn explicit_one(&self) -> Option<&T>
 
pub fn explicit_one(&self) -> Option<&T>
The value used when the PluralOperands are exactly 1.
Sourcepub fn map<B, F: FnMut(T) -> B>(self, f: F) -> PluralElements<B>
 
pub fn map<B, F: FnMut(T) -> B>(self, f: F) -> PluralElements<B>
Applies a function f to convert all values to another type.
§Examples
use icu_plurals::PluralElements;
let x = PluralElements::new(11).with_one_value(Some(15));
let y = x.map(|i| i * 2);
assert_eq!(*y.other(), 22);
assert_eq!(*y.one(), 30);Sourcepub fn try_map<B, E, F: FnMut(T) -> Result<B, E>>(
    self,
    f: F,
) -> Result<PluralElements<B>, E>
 
pub fn try_map<B, E, F: FnMut(T) -> Result<B, E>>( self, f: F, ) -> Result<PluralElements<B>, E>
Applies a function f to convert all values to another type,
propagating a possible error.
Sourcepub fn try_for_each<E, F: FnMut(&T) -> Result<(), E>>(
    &self,
    f: F,
) -> Result<(), E>
 
pub fn try_for_each<E, F: FnMut(&T) -> Result<(), E>>( &self, f: F, ) -> Result<(), E>
Immutably applies a function f to each value,
propagating a possible error.
Sourcepub fn for_each_mut<F: FnMut(&mut T)>(&mut self, f: F)
 
pub fn for_each_mut<F: FnMut(&mut T)>(&mut self, f: F)
Mutably applies a function f to each value.
§Examples
use icu_plurals::PluralElements;
let mut x = PluralElements::new(11).with_one_value(Some(15));
x.for_each_mut(|i| *i *= 2);
assert_eq!(*x.other(), 22);
assert_eq!(*x.one(), 30);Sourcepub fn try_for_each_mut<E, F: FnMut(&mut T) -> Result<(), E>>(
    &mut self,
    f: F,
) -> Result<(), E>
 
pub fn try_for_each_mut<E, F: FnMut(&mut T) -> Result<(), E>>( &mut self, f: F, ) -> Result<(), E>
Mutably applies a function f to each value,
propagating a possible error.
Sourcepub fn as_ref(&self) -> PluralElements<&T>
 
pub fn as_ref(&self) -> PluralElements<&T>
Converts from &PluralElements<T> to PluralElements<&T>.
Source§impl<T: PartialEq> PluralElements<T>
 
impl<T: PartialEq> PluralElements<T>
Sourcepub fn with_zero_value(self, zero: Option<T>) -> Self
 
pub fn with_zero_value(self, zero: Option<T>) -> Self
Sets the value for PluralCategory::Zero.
Sourcepub fn with_one_value(self, one: Option<T>) -> Self
 
pub fn with_one_value(self, one: Option<T>) -> Self
Sets the value for PluralCategory::One.
Sourcepub fn with_two_value(self, two: Option<T>) -> Self
 
pub fn with_two_value(self, two: Option<T>) -> Self
Sets the value for PluralCategory::Two.
Sourcepub fn with_few_value(self, few: Option<T>) -> Self
 
pub fn with_few_value(self, few: Option<T>) -> Self
Sets the value for PluralCategory::Few.
Sourcepub fn with_many_value(self, many: Option<T>) -> Self
 
pub fn with_many_value(self, many: Option<T>) -> Self
Sets the value for PluralCategory::Many.
Sourcepub fn with_explicit_zero_value(self, explicit_zero: Option<T>) -> Self
 
pub fn with_explicit_zero_value(self, explicit_zero: Option<T>) -> Self
Sets the value for explicit 0.
Sourcepub fn with_explicit_one_value(self, explicit_one: Option<T>) -> Self
 
pub fn with_explicit_one_value(self, explicit_one: Option<T>) -> Self
Sets the value for explicit 1.
Trait Implementations§
Source§impl<T: Clone> Clone for PluralElements<T>
 
impl<T: Clone> Clone for PluralElements<T>
Source§fn clone(&self) -> PluralElements<T>
 
fn clone(&self) -> PluralElements<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for PluralElements<T>
 
impl<T: Debug> Debug for PluralElements<T>
Source§impl<T, V> EncodeAsVarULE<PluralElementsPackedULE<V>> for PluralElements<(FourBitMetadata, T)>
 
impl<T, V> EncodeAsVarULE<PluralElementsPackedULE<V>> for PluralElements<(FourBitMetadata, T)>
Source§fn encode_var_ule_as_slices<R>(&self, _cb: impl FnOnce(&[&[u8]]) -> R) -> R
 
fn encode_var_ule_as_slices<R>(&self, _cb: impl FnOnce(&[&[u8]]) -> R) -> R
cb with a piecewise list of byte slices that when concatenated
produce the memory pattern of the corresponding instance of T. Read moreSource§fn encode_var_ule_len(&self) -> usize
 
fn encode_var_ule_len(&self) -> usize
VarULE typeSource§fn encode_var_ule_write(&self, dst: &mut [u8])
 
fn encode_var_ule_write(&self, dst: &mut [u8])
VarULE type to the dst buffer. dst should
be the size of Self::encode_var_ule_len()Source§impl<T, V> From<PluralElements<T>> for PluralElementsPackedCow<'static, V>
 
impl<T, V> From<PluralElements<T>> for PluralElementsPackedCow<'static, V>
Source§fn from(value: PluralElements<T>) -> Self
 
fn from(value: PluralElements<T>) -> Self
Source§impl<T: PartialEq> PartialEq for PluralElements<T>
 
impl<T: PartialEq> PartialEq for PluralElements<T>
impl<T: Eq> Eq for PluralElements<T>
impl<T> StructuralPartialEq for PluralElements<T>
Auto Trait Implementations§
impl<T> Freeze for PluralElements<T>where
    T: Freeze,
impl<T> RefUnwindSafe for PluralElements<T>where
    T: RefUnwindSafe,
impl<T> Send for PluralElements<T>where
    T: Send,
impl<T> Sync for PluralElements<T>where
    T: Sync,
impl<T> Unpin for PluralElements<T>where
    T: Unpin,
impl<T> UnwindSafe for PluralElements<T>where
    T: 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> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
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