pub enum Multi<T> {
One(T),
Many(Vec<T>),
}
pub trait AsMultiIterator<T>: Iterator<Item = Multi<T>> {}
pub trait MultiIterator {
type Item;
fn next(&mut self) -> Option<Multi<Self::Item>>;
fn into_iter(self) -> impl Iterator<Item = Multi<Self::Item>>
where
Self: Sized + 'static,
{
MultiAsIterator(Box::new(self))
}
}
pub struct MultiAsIterator<T>(Box<dyn MultiIterator<Item = T>>);
impl<T> MultiAsIterator<T> {
pub fn from_impl(t: impl MultiIterator<Item = T> + 'static) -> Self {
Self(Box::new(t))
}
#[must_use]
pub fn new(t: Box<dyn MultiIterator<Item = T>>) -> Self {
Self(t)
}
}
impl<T> AsMultiIterator<T> for MultiAsIterator<T> {}
impl<T> Iterator for MultiAsIterator<T> {
type Item = Multi<T>;
fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
}