Skip to content

Commit

Permalink
Rename to
Browse files Browse the repository at this point in the history
  • Loading branch information
cdbrkfxrpt committed Aug 3, 2024
1 parent abd26e2 commit a5b41dc
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/maybe_multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::Multiple;
)]
pub enum MaybeMultiple<T> {
None,
Some(T),
Single(T),
Multiple(Multiple<T>),
}

Expand All @@ -27,8 +27,8 @@ impl<T> MaybeMultiple<T> {

#[must_use = "to assert that this has a value, wrap this in an `assert!()` instead"]
#[inline]
pub fn is_some(&self) -> bool {
matches!(self, Self::Some(_))
pub fn is_single(&self) -> bool {
matches!(self, Self::Single(_))
}

#[must_use = "to assert that this has a value, wrap this in an `assert!()` instead"]
Expand All @@ -40,7 +40,7 @@ impl<T> MaybeMultiple<T> {
/// Collapses a [`Vec`] into a [`MaybeMultiple`].
///
/// This function collapses an empty [`Vec`] into [`MaybeMultiple::None`], a single element
/// [`Vec`] into [`MaybeMultiple::Some`], and a multiple element [`Vec`] into
/// [`Vec`] into [`MaybeMultiple::Single`], and a multiple element [`Vec`] into
/// [`MaybeMultiple::Multiple`]. The [`Vec`] is consumed.
///
/// This function is provided in lue of `impl From<Vec<T>> for MaybeMultiple<T>`, which would
Expand All @@ -58,7 +58,7 @@ impl<T> MaybeMultiple<T> {
/// assert!(maybe_multiple.is_none());
///
/// let maybe_multiple = MaybeMultiple::collapse_vec_into(vec![42]);
/// assert!(maybe_multiple.is_some());
/// assert!(maybe_multiple.is_single());
///
/// let maybe_multiple = MaybeMultiple::collapse_vec_into(vec![42, 43, 44]);
/// assert!(maybe_multiple.is_multiple());
Expand All @@ -67,7 +67,7 @@ impl<T> MaybeMultiple<T> {
pub fn collapse_vec_into(mut v: Vec<T>) -> Self {
match v.len() {
0 => Self::None,
1 => Self::Some(v.pop().expect("input vec has one element")),
1 => Self::Single(v.pop().expect("input vec has one element")),
_ => Self::Multiple(v.try_into().expect("input vec has more than one element")),
}
}
Expand All @@ -77,7 +77,7 @@ impl<T> MaybeMultiple<T> {
pub fn expand_into_vec(self) -> Vec<T> {
match self {
Self::None => vec![],
Self::Some(v) => vec![v],
Self::Single(v) => vec![v],
Self::Multiple(m) => m.into(),
}
}
Expand All @@ -95,7 +95,7 @@ impl<T> Default for MaybeMultiple<T> {

impl<T> From<T> for MaybeMultiple<T> {
fn from(t: T) -> Self {
Self::Some(t)
Self::Single(t)
}
}

Expand Down Expand Up @@ -124,9 +124,9 @@ mod tests {
let e = v[0];
assert_eq!(
MaybeMultiple::collapse_vec_into(v.clone()),
MaybeMultiple::Some(e)
MaybeMultiple::Single(e)
);
assert_eq!(MaybeMultiple::Some(e).expand_into_vec(), v);
assert_eq!(MaybeMultiple::Single(e).expand_into_vec(), v);
}
_ => {
assert_eq!(
Expand Down Expand Up @@ -154,8 +154,8 @@ mod tests {
}

#[proptest]
fn serialize_deserialize_some(val: u8) {
let maybe_multiple = MaybeMultiple::Some(val);
fn serialize_deserialize_single(val: u8) {
let maybe_multiple = MaybeMultiple::Single(val);
assert_eq!(
serde_json::to_string(&maybe_multiple).unwrap(),
serde_json::to_string(&val).unwrap()
Expand Down

0 comments on commit a5b41dc

Please sign in to comment.