pub trait IteratorExtensions: Iterator + Sized {
fn try_map<U, E, F>(self, f: F) -> Result<impl Iterator<Item = U>, E>
where
F: FnMut(Self::Item) -> Result<U, E>,
{
Ok(self.map(f).collect::<Result<Vec<U>, E>>()?.into_iter())
}
fn to_vec(self) -> Vec<Self::Item> {
self.collect()
}
}
impl<I: Iterator + Sized> IteratorExtensions for I {}