pub struct OneOrMany<T> { /* private fields */ }Expand description
Struct containing either a single item or a list of items of type T.
If a single item is present, first will contain it and rest will be empty.
If multiple items are present, first will contain the first item and rest will contain the rest.
IMPORTANT: this struct cannot be created with an empty vector.
OneOrMany objects can only be created using OneOrMany::from() or OneOrMany::try_from().
Implementations§
Source§impl<T: Clone> OneOrMany<T>
impl<T: Clone> OneOrMany<T>
Sourcepub fn push(&mut self, item: T)
pub fn push(&mut self, item: T)
After OneOrMany<T> is created, add an item of type T to the rest.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
If OneOrMany<T> is empty. This will always be false because you cannot create an empty OneOrMany<T>.
This method is required when the method len exists.
Sourcepub fn many(items: Vec<T>) -> Result<Self, EmptyListError>
pub fn many(items: Vec<T>) -> Result<Self, EmptyListError>
Create a OneOrMany object with a vector of items of any type.
Sourcepub fn merge(
one_or_many_items: Vec<OneOrMany<T>>,
) -> Result<Self, EmptyListError>
pub fn merge( one_or_many_items: Vec<OneOrMany<T>>, ) -> Result<Self, EmptyListError>
Merge a list of OneOrMany items into a single OneOrMany item.
pub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
Trait Implementations§
Source§impl<T: Clone> IntoIterator for OneOrMany<T>
Implement Iterator for IntoIter<T>.
impl<T: Clone> IntoIterator for OneOrMany<T>
Implement Iterator for IntoIter<T>.
impl<T: Eq> Eq for OneOrMany<T>
impl<T> StructuralPartialEq for OneOrMany<T>
Auto Trait Implementations§
impl<T> Freeze for OneOrMany<T>where
T: Freeze,
impl<T> RefUnwindSafe for OneOrMany<T>where
T: RefUnwindSafe,
impl<T> Send for OneOrMany<T>where
T: Send,
impl<T> Sync for OneOrMany<T>where
T: Sync,
impl<T> Unpin for OneOrMany<T>where
T: Unpin,
impl<T> UnwindSafe for OneOrMany<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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.