Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Sep 8, 2024
1 parent edfcac6 commit 1f5b134
Show file tree
Hide file tree
Showing 2 changed files with 233 additions and 99 deletions.
94 changes: 53 additions & 41 deletions components/plurals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ pub struct PluralElements<'a, T: ?Sized> {
explicit_one: Option<&'a T>,
}

impl<'a, T: ?Sized + PartialEq> PluralElements<'a, T> {
impl<'a, T: ?Sized> PluralElements<'a, T> {
/// Creates a new [`PluralElements`] with the given default value.
pub fn new(other: &'a T) -> Self {
Self {
Expand All @@ -904,6 +904,58 @@ impl<'a, T: ?Sized + PartialEq> PluralElements<'a, T> {
}
}

/// The value for [`PluralCategory::Zero`]
pub fn zero(&self) -> &'a T {
self.zero.unwrap_or(self.other)
}

/// The value for [`PluralCategory::One`]
pub fn one(&self) -> &'a T {
self.one.unwrap_or(self.other)
}

/// The value for [`PluralCategory::Two`]
pub fn two(&self) -> &'a T {
self.two.unwrap_or(self.other)
}

/// The value for [`PluralCategory::Few`]
pub fn few(&self) -> &'a T {
self.few.unwrap_or(self.other)
}

/// The value for [`PluralCategory::Many`]
pub fn many(&self) -> &'a T {
self.many.unwrap_or(self.other)
}

/// The value for [`PluralCategory::Other`]
pub fn other(&self) -> &'a T {
self.other
}

/// The value used when the [`PluralOperands`] are exactly 0.
pub fn explicit_zero(&self) -> Option<&'a T> {
self.explicit_zero
}

/// The value used when the [`PluralOperands`] are exactly 1.
pub fn explicit_one(&self) -> Option<&'a T> {
self.explicit_one
}

pub(crate) fn has_specials(&self) -> bool {
self.zero.is_some()
|| self.one.is_some()
|| self.two.is_some()
|| self.few.is_some()
|| self.many.is_some()
|| self.explicit_zero.is_some()
|| self.explicit_one.is_some()
}
}

impl<'a, T: ?Sized + PartialEq> PluralElements<'a, T> {
/// Sets the value for [`PluralCategory::Zero`].
pub fn with_zero_value(self, zero: Option<&'a T>) -> Self {
Self {
Expand Down Expand Up @@ -959,44 +1011,4 @@ impl<'a, T: ?Sized + PartialEq> PluralElements<'a, T> {
..self
}
}

/// The value for [`PluralCategory::Zero`]
pub fn zero(&self) -> &'a T {
self.zero.unwrap_or(self.other)
}

/// The value for [`PluralCategory::One`]
pub fn one(&self) -> &'a T {
self.one.unwrap_or(self.other)
}

/// The value for [`PluralCategory::Two`]
pub fn two(&self) -> &'a T {
self.two.unwrap_or(self.other)
}

/// The value for [`PluralCategory::Few`]
pub fn few(&self) -> &'a T {
self.few.unwrap_or(self.other)
}

/// The value for [`PluralCategory::Many`]
pub fn many(&self) -> &'a T {
self.many.unwrap_or(self.other)
}

/// The value for [`PluralCategory::Other`]
pub fn other(&self) -> &'a T {
self.other
}

/// The value used when the [`PluralOperands`] are exactly 0.
pub fn explicit_zero(&self) -> Option<&'a T> {
self.explicit_zero
}

/// The value used when the [`PluralOperands`] are exactly 1.
pub fn explicit_one(&self) -> Option<&'a T> {
self.explicit_one
}
}
Loading

0 comments on commit 1f5b134

Please sign in to comment.