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>

source

pub fn new(other: T) -> PluralElements<T>

Creates a new PluralElements with the given default value.

source

pub fn zero(&self) -> &T

The value for PluralCategory::Zero

source

pub fn one(&self) -> &T

The value for PluralCategory::One

source

pub fn two(&self) -> &T

The value for PluralCategory::Two

source

pub fn few(&self) -> &T

The value for PluralCategory::Few

source

pub fn many(&self) -> &T

The value for PluralCategory::Many

source

pub fn other(&self) -> &T

The value for PluralCategory::Other

source

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);
source

pub fn explicit_zero(&self) -> Option<&T>

The value used when the PluralOperands are exactly 0.

source

pub fn explicit_one(&self) -> Option<&T>

The value used when the PluralOperands are exactly 1.

source

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.

source

pub fn as_ref(&self) -> PluralElements<&T>

Converts from &PluralElements<T> to PluralElements<&T>.

source§

impl<T> PluralElements<T>
where T: PartialEq,

source

pub fn with_zero_value(self, zero: Option<T>) -> PluralElements<T>

Sets the value for PluralCategory::Zero.

source

pub fn with_one_value(self, one: Option<T>) -> PluralElements<T>

Sets the value for PluralCategory::One.

source

pub fn with_two_value(self, two: Option<T>) -> PluralElements<T>

Sets the value for PluralCategory::Two.

source

pub fn with_few_value(self, few: Option<T>) -> PluralElements<T>

Sets the value for PluralCategory::Few.

source

pub fn with_many_value(self, many: Option<T>) -> PluralElements<T>

Sets the value for PluralCategory::Many.

source

pub fn with_explicit_zero_value( self, explicit_zero: Option<T>, ) -> PluralElements<T>

Sets the value for explicit 0.

source

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,

source§

fn clone(&self) -> PluralElements<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for PluralElements<T>
where T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<T, V> EncodeAsVarULE<PluralElementsPackedULE<V>> for PluralElements<(FourBitMetadata, T)>
where T: PartialEq + Debug, &'a T: for<'a> EncodeAsVarULE<V>, V: VarULE + ?Sized,

source§

fn encode_var_ule_as_slices<R>(&self, _cb: impl FnOnce(&[&[u8]]) -> R) -> R

Calls cb with a piecewise list of byte slices that when concatenated produce the memory pattern of the corresponding instance of T. Read more
source§

fn encode_var_ule_len(&self) -> usize

Return the length, in bytes, of the corresponding VarULE type
source§

fn encode_var_ule_write(&self, dst: &mut [u8])

Write the corresponding 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>
where V: VarULE + ?Sized, T: PartialEq + Debug, &'a T: for<'a> EncodeAsVarULE<V>,

source§

fn from(value: PluralElements<T>) -> PluralElementsPackedCow<'static, V>

Converts to this type from the input type.
source§

impl<T> PartialEq for PluralElements<T>
where T: PartialEq,

source§

fn eq(&self, other: &PluralElements<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Eq for PluralElements<T>
where T: Eq,

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T
where T: Send + Sync,