pub trait IteratorExt {
    fn parallel_map<F, O>(
        self,
        f: F
    ) -> ParallelMap<'static, 'static, Self, O, F>
Notable traits for ParallelMap<'env, 'scope, I, O, F>
impl<'env, 'scope, I, O, F> Iterator for ParallelMap<'env, 'scope, I, O, F> where
    I: Iterator + 'env + 'scope,
    I::Item: Send + 'env + 'scope,
    O: Send + 'env + 'scope,
    F: FnMut(I::Item) -> O + 'env + 'scope,
    F: Clone + Send
type Item = O;

    where
        Self: Sized,
        Self: Iterator,
        O: 'static,
        F: FnMut(Self::Item) -> O + Send + 'static
;
fn parallel_map_scoped<'env, 'scope, F, O>(
        self,
        scope: &'scope Scope<'env>,
        f: F
    ) -> ParallelMap<'env, 'scope, Self, O, F>
Notable traits for ParallelMap<'env, 'scope, I, O, F>
impl<'env, 'scope, I, O, F> Iterator for ParallelMap<'env, 'scope, I, O, F> where
    I: Iterator + 'env + 'scope,
    I::Item: Send + 'env + 'scope,
    O: Send + 'env + 'scope,
    F: FnMut(I::Item) -> O + 'env + 'scope,
    F: Clone + Send
type Item = O;

    where
        Self: Sized,
        Self: Iterator + 'scope + 'env,
        F: FnMut(Self::Item) -> O + 'scope + 'env + Send
;
fn parallel_filter<F>(self, f: F) -> ParallelFilter<'static, 'static, Self>
Notable traits for ParallelFilter<'env, 'scope, I>
impl<'env, 'scope, I> Iterator for ParallelFilter<'env, 'scope, I> where
    I: Iterator + 'env + 'scope,
    I::Item: Send + 'env + 'scope,
    'env: 'scope, 
type Item = I::Item;

    where
        Self: Sized,
        Self: Iterator + Send,
        F: FnMut(&Self::Item) -> bool + Send + 'static + Clone,
        Self::Item: Send + 'static
;
fn parallel_filter_scoped<'env, 'scope, F>(
        self,
        scope: &'scope Scope<'env>,
        f: F
    ) -> ParallelFilter<'env, 'scope, Self>
Notable traits for ParallelFilter<'env, 'scope, I>
impl<'env, 'scope, I> Iterator for ParallelFilter<'env, 'scope, I> where
    I: Iterator + 'env + 'scope,
    I::Item: Send + 'env + 'scope,
    'env: 'scope, 
type Item = I::Item;

    where
        Self: Sized,
        Self: Iterator + Send + 'scope + 'env,
        F: FnMut(&Self::Item) -> bool + Send + 'env + 'scope + Clone,
        Self::Item: Send + 'env + 'scope
;
fn readahead(self, buffer_size: usize) -> Readahead<'static, 'static, Self>
Notable traits for Readahead<'env, 'scope, I>
impl<'env, 'scope, I> Iterator for Readahead<'env, 'scope, I> where
    I: Iterator + 'env + 'scope,
    I: Send + 'env + 'scope,
    I::Item: Send + 'env + 'scope, 
type Item = I::Item;

    where
        Self: Iterator,
        Self: Sized,
        Self: Send + 'static,
        Self::Item: Send + 'static
;
fn readahead_scoped<'env, 'scope>(
        self,
        scope: &'scope Scope<'env>,
        buffer_size: usize
    ) -> Readahead<'env, 'scope, Self>
Notable traits for Readahead<'env, 'scope, I>
impl<'env, 'scope, I> Iterator for Readahead<'env, 'scope, I> where
    I: Iterator + 'env + 'scope,
    I: Send + 'env + 'scope,
    I::Item: Send + 'env + 'scope, 
type Item = I::Item;

    where
        Self: Sized + Send,
        Self: Iterator + 'scope + 'env,
        Self::Item: Send + 'env + 'scope
;
fn readahead_profiled<TxP: Profiler, RxP: Profiler>(
        self,
        buffer_size: usize,
        tx_profiler: TxP,
        rx_profiler: RxP
    ) -> ProfileIngress<Readahead<'static, 'static, ProfileEgress<Self, TxP>>, RxP>
Notable traits for ProfileIngress<I, P>
impl<I, P> Iterator for ProfileIngress<I, P> where
    I: Iterator,
    P: Profiler
type Item = I::Item;

    where
        Self: Iterator,
        Self: Sized,
        Self: Send + 'static,
        Self::Item: Send + 'static,
        TxP: Send + 'static
;
fn readahead_scoped_profiled<'env, 'scope, TxP: Profiler, RxP: Profiler>(
        self,
        scope: &'scope Scope<'env>,
        buffer_size: usize,
        tx_profiler: TxP,
        rx_profiler: RxP
    ) -> ProfileIngress<Readahead<'env, 'scope, ProfileEgress<Self, TxP>>, RxP>
Notable traits for ProfileIngress<I, P>
impl<I, P> Iterator for ProfileIngress<I, P> where
    I: Iterator,
    P: Profiler
type Item = I::Item;

    where
        Self: Sized + Send,
        Self: Iterator + 'scope + 'env,
        Self::Item: Send + 'env + 'scope,
        TxP: Send + 'static
;
fn profile_egress<P: Profiler>(self, profiler: P) -> ProfileEgress<Self, P>
Notable traits for ProfileEgress<I, P>
impl<I, P> Iterator for ProfileEgress<I, P> where
    I: Iterator,
    P: Profiler
type Item = I::Item;

    where
        Self: Iterator,
        Self: Sized
;
fn profile_ingress<P: Profiler>(
        self,
        profiler: P
    ) -> ProfileIngress<Self, P>
Notable traits for ProfileIngress<I, P>
impl<I, P> Iterator for ProfileIngress<I, P> where
    I: Iterator,
    P: Profiler
type Item = I::Item;

    where
        Self: Iterator,
        Self: Sized
; }
Expand description

Extension trait for std::iter::Iterator bringing parallel operations

TODO

  • parallel_for_each
  • parallel_flat_map
  • possibly others

PRs welcome

Required methods

Run map function in parallel on multiple threads

Results will be returned in order.

No worker threads will be started and no items will be pulled unless ParallelMap::started was called, or until first time ParallelMap is pulled for elements with ParallelMap::next. In that respect, ParallelMap behaves like every other iterator and is lazy.

Default built-in thread pool will be used unless ParallelMap::threads is used.

Scoped version of IteratorExt::parallel_map

Use when you want to process in parallel items that contain borrowed references.

See scope.

Run filter function in parallel on multiple threads

A wrapper around IteratorExt::parallel_map really, so it has similiar properties.

Scoped version of IteratorExt::parallel_filter

Use when you want to process in parallel items that contain borrowed references.

See scope.

Run the current iterator in another thread and return elements through a buffered channel.

buffer_size defines the size of the output channel connecting current and the inner thread. It’s a common mistake to use large channel sizes needlessly in hopes of achieving higher performance. The only benefit large buffer size value provides is smooting out the variance of the inner iterator returning items. The cost - wasting memory. In normal circumstances 0 is recommended.

Scoped version of IteratorExt::readahead

Use when you want to process in parallel items that contain borrowed references.

See scope.

Profiled version of IteratorExt::readahead

Literally .profile_egress(tx_profiler).readahead(n).profile_ingress(rx_profiler)

See Profiler for more info.

Profiled version of IteratorExt::readahead_scoped

Literally .profile_egress(tx_profiler).readahead_scoped(scope, n).profile_ingress(rx_profiler)

See Profiler for more info.

Profile the time it takes downstream iterator step to consume the returned items.

See ProfileEgress and profile::Profiler.

Profile the time it takes upstream iterator step to produce the returned items.

See ProfileIngress and profile::Profiler.

Implementors