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 insert(&mut self, index: usize, item: T)
pub fn insert(&mut self, index: usize, item: T)
After OneOrMany<T> is created, insert an item of type T at an index.
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<I>(items: I) -> Result<Self, EmptyListError>where
I: IntoIterator<Item = T>,
pub fn many<I>(items: I) -> Result<Self, EmptyListError>where
I: IntoIterator<Item = T>,
Create a OneOrMany object with a vector of items of any type.
Sourcepub fn merge<I>(one_or_many_items: I) -> Result<Self, EmptyListError>where
I: IntoIterator<Item = OneOrMany<T>>,
pub fn merge<I>(one_or_many_items: I) -> Result<Self, EmptyListError>where
I: IntoIterator<Item = OneOrMany<T>>,
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<'de, T> Deserialize<'de> for OneOrMany<T>where
T: Deserialize<'de> + Clone,
impl<'de, T> Deserialize<'de> for OneOrMany<T>where
T: Deserialize<'de> + Clone,
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<OneOrMany<AssistantContent>> for Message
impl From<OneOrMany<AssistantContent>> for Message
Source§fn from(content: OneOrMany<AssistantContent>) -> Self
fn from(content: OneOrMany<AssistantContent>) -> Self
Source§impl From<OneOrMany<UserContent>> for Message
impl From<OneOrMany<UserContent>> for Message
Source§fn from(content: OneOrMany<UserContent>) -> Self
fn from(content: OneOrMany<UserContent>) -> Self
Source§impl<T> IntoIterator for OneOrMany<T>where
T: Clone,
Implement Iterator for IntoIter<T>.
impl<T> IntoIterator for OneOrMany<T>where
T: Clone,
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> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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