pub trait FromParallelIterator<'a, I>: Send + Sizedwhere
I: Send + 'a,{
type ExecutorItem2: Send + 'a;
type ExecutorItem3: Send + 'a;
// Required method
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>;
}Expand description
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);Required Associated Types§
type ExecutorItem2: Send + 'a
type ExecutorItem3: Send + 'a
Required Methods§
Sourcefn from_par_iter<E, X>(executor: E, iterator: X) -> E::Resultwhere
E: Executor<'a, Self, Self::ExecutorItem2, Self::ExecutorItem3>,
X: IntoParallelIterator<'a, Item = I>,
fn from_par_iter<E, X>(executor: E, iterator: X) -> E::Resultwhere
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.