pub struct ZipLongestIter<T, U> {
a: T,
b: U,
}
impl<T, U> Iterator for ZipLongestIter<T, U>
where
T: Iterator,
U: Iterator,
{
type Item = (Option<T::Item>, Option<U::Item>);
fn next(&mut self) -> Option<Self::Item> {
match (self.a.next(), self.b.next()) {
(None, None) => None,
(a, b) => Some((a, b)),
}
}
}
pub trait ZipLongest {
fn zip_longest<U>(self, other: U) -> ZipLongestIter<Self, U>
where
Self: Sized,
U: IntoIterator;
}
impl<T> ZipLongest for T
where
T: Iterator,
{
fn zip_longest<U>(self, other: U) -> ZipLongestIter<Self, U>
where
U: IntoIterator,
{
ZipLongestIter { a: self, b: other }
}
}