pub trait IteratorExt {
    type Item;
    type IntoIter: NonEmptyIterator<Item = Self::Item>;

    // Required method
    fn to_nonempty_iter(self) -> Option<Self::IntoIter>;
}
Expand description

Convenience trait extending Iterator.

Required Associated Types§

source

type Item

The type of the elements being iterated over.

source

type IntoIter: NonEmptyIterator<Item = Self::Item>

Which kind of NonEmptyIterator are we turning this into?

Required Methods§

source

fn to_nonempty_iter(self) -> Option<Self::IntoIter>

Tries to convert self into a NonEmptyIterator.

use nonempty_collections::*;

let a = vec![1];
let x = a.into_iter().to_nonempty_iter();
assert!(x.is_some());

let y = x.unwrap().collect::<NEVec<_>>();
assert_eq!(y.len().get(), 1);
use nonempty_collections::*;

let b: Vec::<u8> = vec![];
let x = b.into_iter().to_nonempty_iter();

assert!(x.is_none());

To construct non-empty collections directly, consider macros like crate::nev!.

Implementors§

source§

impl<I, T> IteratorExt for I
where I: Iterator<Item = T>,

§

type Item = T

§

type IntoIter = Chain<Once<<I as IteratorExt>::Item>, I>