pub trait IntoParallelIteratorSync<R, T, TL, F>where
F: Send + Clone + 'static + Fn(T) -> Result<R, ()>,
T: Send + 'static,
TL: Send + IntoIterator<Item = T> + 'static,
<TL as IntoIterator>::IntoIter: Send + 'static,
R: Send,{
// Required method
fn into_par_iter_sync(self, func: F) -> ParIterSync<R> ⓘ;
}Expand description
lock-free sequential parallel iterator
Required Methods§
Sourcefn into_par_iter_sync(self, func: F) -> ParIterSync<R> ⓘ
fn into_par_iter_sync(self, func: F) -> ParIterSync<R> ⓘ
§Usage
This method executes func in parallel.
The func is a closure that takes the returned elements
from the upstream iterator as argument and returns
some Result(R, ()).
This iterator would return type R when it gets Ok(R)
and stops when it gets an Err(()).
§Example
use par_iter_sync::IntoParallelIteratorSync;
let mut count = 0;
// for loop
for i in (0..100).into_par_iter_sync(|i| Ok(i)) {
assert_eq!(i, count);
count += 1;
}
// sum
let sum: i32 = (1..=100).into_par_iter_sync(|i| Ok(i)).sum();
// take and collect
let results: Vec<i32> = (0..10).into_par_iter_sync(|i| Ok(i)).take(5).collect();
assert_eq!(sum, 5050);
assert_eq!(results, vec![0, 1, 2, 3, 4])If the result is not polled using next(),
the parallel execution will stop and wait.
§Sequential Consistency
The output order is guaranteed to be the same as the provided iterator.
See crate module-level doc.