[][src]Trait asparit::FromParallelIterator

pub trait FromParallelIterator<'a, I>: Send + Sized where
    I: Send + 'a, 
{ type ExecutorItem2: Send + 'a; type ExecutorItem3: Send + 'a; pub fn from_par_iter<E, X>(executor: E, iterator: X) -> E::Result
    where
        E: Executor<'a, Self, Self::ExecutorItem2, Self::ExecutorItem3>,
        X: IntoParallelIterator<'a, Item = I>
; }

FromParallelIterator implements the creation of a collection from a ParallelIterator. By implementing FromParallelIterator for a given type, you define how it will be created from an iterator.

FromParallelIterator is used through ParallelIterator's collect() method.

Examples

Implementing FromParallelIterator for your type:

use asparit::*;
use std::mem;

struct BlackHole {
    mass: usize,
}

impl<'a, I> FromParallelIterator<'a, I> for BlackHole
where
    I: Send + 'a,
{
    type ExecutorItem2 = usize;
    type ExecutorItem3 = ();

    fn from_par_iter<E, X>(executor: E, iterator: X) -> E::Result
    where
        E: Executor<'a, Self, Self::ExecutorItem2, Self::ExecutorItem3>,
        X: IntoParallelIterator<'a, Item = I>,
    {
        let iterator = iterator.into_par_iter();
        let executor = executor.into_inner();

        let ret = iterator.count().exec_with(executor);

        E::map(ret, |count| BlackHole {
            mass: count * std::mem::size_of::<I>(),
        })
    }
}

let bh: BlackHole = (0i32..1000).into_par_iter().collect().exec();
assert_eq!(bh.mass, 4000);

Associated Types

type ExecutorItem2: Send + 'a

type ExecutorItem3: Send + 'a

Loading content...

Required methods

pub fn from_par_iter<E, X>(executor: E, iterator: X) -> E::Result where
    E: Executor<'a, Self, Self::ExecutorItem2, Self::ExecutorItem3>,
    X: IntoParallelIterator<'a, Item = I>, 

Creates an instance of the collection from the parallel iterator iterator.

If your collection is not naturally parallel, the easiest (and fastest) way to do this is often to collect iterator into a LinkedList or other intermediate data structure and then sequentially extend your collection. However, a more 'native' technique is to use the iterator.fold or iterator.fold_with methods to create the collection. Alternatively, if your collection is 'natively' parallel, you can use iterator.for_each to process each element in turn.

Loading content...

Implementations on Foreign Types

impl<'a> FromParallelIterator<'a, ()> for ()[src]

type ExecutorItem2 = ()

type ExecutorItem3 = ()

impl<'a, I> FromParallelIterator<'a, I> for Vec<I> where
    I: Send + 'a, 
[src]

type ExecutorItem2 = VecExtendResult<Vec<I>>

type ExecutorItem3 = ()

Loading content...

Implementors

Loading content...