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> OneOrMany<T>where
T: Clone,
impl<T> OneOrMany<T>where
T: Clone,
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<OneOrMany<T>, EmptyListError>where
I: IntoIterator<Item = T>,
pub fn many<I>(items: I) -> Result<OneOrMany<T>, 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<OneOrMany<T>, EmptyListError>where
I: IntoIterator<Item = OneOrMany<T>>,
pub fn merge<I>(one_or_many_items: I) -> Result<OneOrMany<T>, EmptyListError>where
I: IntoIterator<Item = OneOrMany<T>>,
Merge a list of OneOrMany items into a single OneOrMany item.
Sourcepub fn from_iter_optional<I>(items: I) -> Option<OneOrMany<T>>where
I: IntoIterator<Item = T>,
pub fn from_iter_optional<I>(items: I) -> Option<OneOrMany<T>>where
I: IntoIterator<Item = T>,
Build a OneOrMany from an iterator when the caller can naturally handle an empty input.
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<OneOrMany<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<OneOrMany<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl<T> Eq for OneOrMany<T>where
T: Eq,
Source§impl From<OneOrMany<ToolResultContent>> for ToolOutput
impl From<OneOrMany<ToolResultContent>> for ToolOutput
Source§fn from(content: OneOrMany<ToolResultContent>) -> ToolOutput
fn from(content: OneOrMany<ToolResultContent>) -> ToolOutput
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>.
Source§impl<T> Serialize for OneOrMany<T>
impl<T> Serialize for OneOrMany<T>
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl<T> StructuralPartialEq for OneOrMany<T>where
T: PartialEq,
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> UnsafeUnpin for OneOrMany<T>where
T: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
impl<T> DebuggableStorage for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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§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.