use super::{Folder, WithSetup};
pub trait Producer: WithSetup + Send + Sized {
type Item;
type IntoIter: Iterator<Item = Self::Item>;
fn into_iter(self) -> Self::IntoIter;
fn split(self) -> (Self, Option<Self>);
fn fold_with<F>(self, folder: F) -> F
where
F: Folder<Self::Item>,
{
folder.consume_iter(self.into_iter())
}
}
#[allow(clippy::len_without_is_empty)]
pub trait IndexedProducer: WithSetup + Send + Sized {
type Item;
type IntoIter: Iterator<Item = Self::Item> + DoubleEndedIterator + ExactSizeIterator;
fn into_iter(self) -> Self::IntoIter;
fn len(&self) -> usize;
fn split_at(self, index: usize) -> (Self, Self);
fn fold_with<F>(self, folder: F) -> F
where
F: Folder<Self::Item>,
{
folder.consume_iter(self.into_iter())
}
}
pub trait WithProducer<'a> {
type Item: Send + 'a;
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
CB: ProducerCallback<'a, Self::Item>;
}
pub trait WithIndexedProducer<'a> {
type Item: Send + 'a;
fn with_indexed_producer<CB>(self, callback: CB) -> CB::Output
where
CB: IndexedProducerCallback<'a, Self::Item>;
}
pub trait ProducerCallback<'p, I> {
type Output;
fn callback<P>(self, producer: P) -> Self::Output
where
P: Producer<Item = I> + 'p;
}
pub trait IndexedProducerCallback<'p, I> {
type Output;
fn callback<P>(self, producer: P) -> Self::Output
where
P: IndexedProducer<Item = I> + 'p;
}