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§

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.

Implementors§

source§

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