pub trait IntoIteratorExt {
type Item;
type IntoIter: NonEmptyIterator<Item = Self::Item>;
// Required method
fn try_into_nonempty_iter(self) -> Option<Self::IntoIter>;
}Expand description
Convenience trait extending IntoIterator.
Required Associated Types§
Sourcetype IntoIter: NonEmptyIterator<Item = Self::Item>
type IntoIter: NonEmptyIterator<Item = Self::Item>
Which kind of NonEmptyIterator are we turning this into?
Required Methods§
Sourcefn try_into_nonempty_iter(self) -> Option<Self::IntoIter>
fn try_into_nonempty_iter(self) -> Option<Self::IntoIter>
Tries to convert self into a NonEmptyIterator.
use nonempty_collections::*;
let a = vec![1];
let x = a.try_into_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.try_into_nonempty_iter();
assert!(x.is_none());To construct non-empty collections directly, consider macros like
crate::nev!.