use crate::{EmptyError, NonEmptyVec};
pub trait IteratorExt: Iterator {
#[cfg(all(any(feature = "alloc", feature = "std"), not(no_global_oom_handling)))]
#[cfg_attr(
doc_cfg,
doc(cfg(all(any(feature = "alloc", feature = "std"), not(no_global_oom_handling))))
)]
#[inline]
#[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead"]
#[track_caller]
unsafe fn collect_nonempty_unchecked(self) -> NonEmptyVec<Self::Item>
where
Self: Sized,
{
let vec = self.collect();
NonEmptyVec::new_unchecked(vec)
}
#[cfg(all(any(feature = "alloc", feature = "std"), not(no_global_oom_handling)))]
#[cfg_attr(
doc_cfg,
doc(cfg(all(any(feature = "alloc", feature = "std"), not(no_global_oom_handling))))
)]
#[inline]
fn collect_nonempty(self) -> Result<NonEmptyVec<Self::Item>, EmptyError>
where
Self: Sized,
{
let vec = self.collect();
NonEmptyVec::new(vec)
}
}
impl<I> IteratorExt for I where I: Iterator {}