Trait mz_ore::collections::CollectionExt
source · pub trait CollectionExt<T>: Sizedwhere
T: IntoIterator,{
// Required methods
fn into_first(self) -> T::Item;
fn into_last(self) -> T::Item;
fn expect_element<Err: Display>(
self,
msg_fn: impl FnOnce() -> Err,
) -> T::Item;
// Provided method
fn into_element(self) -> T::Item { ... }
}
Expand description
Extension methods for collections.
Required Methods§
sourcefn into_first(self) -> T::Item
fn into_first(self) -> T::Item
Consumes the collection and returns its first element.
This method panics if the collection does not have at least one element.
sourcefn into_last(self) -> T::Item
fn into_last(self) -> T::Item
Consumes the collection and returns its last element.
This method panics if the collection does not have at least one element.
sourcefn expect_element<Err: Display>(self, msg_fn: impl FnOnce() -> Err) -> T::Item
fn expect_element<Err: Display>(self, msg_fn: impl FnOnce() -> Err) -> T::Item
Consumes the collection and returns its only element.
This method panics with the given error function’s return value if the collection does not have exactly one element.
Provided Methods§
sourcefn into_element(self) -> T::Item
fn into_element(self) -> T::Item
Consumes the collection and returns its only element.
This method panics if the collection does not have exactly one element.
Object Safety§
This trait is not object safe.