mz_ore::collections

Trait CollectionExt

Source
pub trait CollectionExt<T>: Sized
where 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§

Source

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.

Source

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.

Source

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§

Source

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> CollectionExt<T> for T
where T: IntoIterator,