extern crate crossbeam_channel;
mod tests;
mod panic_guard;
mod ordered;
mod unordered;
pub trait Pipeline<I>
where I: Iterator + Send + 'static, I::Item: Send + 'static
{
fn with_threads(self, num_threads: usize) -> PipelineBuilder<I>;
}
impl<Ii> Pipeline<Ii::IntoIter> for Ii
where Ii: IntoIterator,
Ii::IntoIter: Send + 'static,
Ii::Item: Send + 'static
{
fn with_threads(self, num_threads: usize) -> PipelineBuilder<Ii::IntoIter> {
PipelineBuilder::new(self.into_iter()).num_threads(num_threads)
}
}
pub struct PipelineBuilder<I>
where I: Iterator, I::Item: Send + 'static
{
input: I,
num_threads: usize,
out_buffer: usize,
}
impl<I> PipelineBuilder<I>
where I: Iterator + Send + 'static, I::Item: Send + 'static
{
fn new(iterator: I) -> Self {
PipelineBuilder {
input: iterator,
num_threads: 1,
out_buffer: 0,
}
}
pub fn num_threads(mut self, num_threads: usize) -> Self {
self.num_threads = std::cmp::max(1, num_threads);
self
}
pub fn out_buffer(mut self, size: usize) -> Self {
self.out_buffer = size;
self
}
pub fn map<F, Out>(self, callable: F) -> impl Iterator<Item=Out>
where Out: Send + 'static, F: Fn(I::Item) -> Out + Send + Sync + 'static
{
unordered::PipelineIter::new(self, callable)
}
pub fn ordered_map<F, Out>(self, callable: F) -> impl Iterator<Item=Out>
where Out: Send + 'static, F: Fn(I::Item) -> Out + Send + Sync + 'static
{
ordered::new(self, callable)
}
}