Struct icu::plurals::PluralElements
source · 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) -> PluralElements<T>
pub fn new(other: T) -> PluralElements<T>
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>(self, f: F) -> PluralElements<B>where
F: Fn(T) -> B,
pub fn map<B, F>(self, f: F) -> PluralElements<B>where
F: Fn(T) -> B,
Applies a function f
to map all values to another type.
sourcepub fn as_ref(&self) -> PluralElements<&T>
pub fn as_ref(&self) -> PluralElements<&T>
Converts from &PluralElements<T>
to PluralElements<&T>
.
source§impl<T> PluralElements<T>where
T: PartialEq,
impl<T> PluralElements<T>where
T: PartialEq,
sourcepub fn with_zero_value(self, zero: Option<T>) -> PluralElements<T>
pub fn with_zero_value(self, zero: Option<T>) -> PluralElements<T>
Sets the value for PluralCategory::Zero
.
sourcepub fn with_one_value(self, one: Option<T>) -> PluralElements<T>
pub fn with_one_value(self, one: Option<T>) -> PluralElements<T>
Sets the value for PluralCategory::One
.
sourcepub fn with_two_value(self, two: Option<T>) -> PluralElements<T>
pub fn with_two_value(self, two: Option<T>) -> PluralElements<T>
Sets the value for PluralCategory::Two
.
sourcepub fn with_few_value(self, few: Option<T>) -> PluralElements<T>
pub fn with_few_value(self, few: Option<T>) -> PluralElements<T>
Sets the value for PluralCategory::Few
.
sourcepub fn with_many_value(self, many: Option<T>) -> PluralElements<T>
pub fn with_many_value(self, many: Option<T>) -> PluralElements<T>
Sets the value for PluralCategory::Many
.
sourcepub fn with_explicit_zero_value(
self,
explicit_zero: Option<T>,
) -> PluralElements<T>
pub fn with_explicit_zero_value( self, explicit_zero: Option<T>, ) -> PluralElements<T>
Sets the value for explicit 0.
sourcepub fn with_explicit_one_value(
self,
explicit_one: Option<T>,
) -> PluralElements<T>
pub fn with_explicit_one_value( self, explicit_one: Option<T>, ) -> PluralElements<T>
Sets the value for explicit 1.
Trait Implementations§
source§impl<T> Clone for PluralElements<T>where
T: Clone,
impl<T> Clone for PluralElements<T>where
T: Clone,
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 for PluralElements<T>where
T: Debug,
impl<T> Debug for PluralElements<T>where
T: Debug,
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>) -> PluralElementsPackedCow<'static, V>
fn from(value: PluralElements<T>) -> PluralElementsPackedCow<'static, V>
source§impl<T> PartialEq for PluralElements<T>where
T: PartialEq,
impl<T> PartialEq for PluralElements<T>where
T: PartialEq,
impl<T> Eq for PluralElements<T>where
T: Eq,
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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