Crates.io | parallel-iterator |
lib.rs | parallel-iterator |
version | 0.1.6 |
source | src |
created_at | 2018-12-18 22:17:46.376513 |
updated_at | 2020-07-15 19:56:54.859756 |
description | Parallelize any iterator with ease! |
homepage | |
repository | https://github.com/anderejd/parallel-iterator |
max_upload_size | |
id | 102595 |
size | 27,149 |
Parallelize any iterator!
This code is copy-pasted from examples/example_1.rs
.
extern crate parallel_iterator;
use parallel_iterator::ParallelIterator;
fn do_some_work(i: u32) -> u32 {
i + 1 // let's pretend this is a heavy calculation
}
fn main() {
for i in ParallelIterator::new(|| (0u32..100), || do_some_work) {
println!("Got a result: {}!", i);
}
}
This code is copy-pasted from examples/example_2.rs
.
extern crate parallel_iterator;
use parallel_iterator::ParallelIterator;
fn do_some_work(i: usize, out: &mut Vec<usize>) {
for j in 0..i {
out.push(j); // The caller can pre-allocate.
}
}
fn main() {
const MAX: usize = 1000;
let xform_ctor = || {
let mut buffer = Vec::with_capacity(MAX);
move |i| {
buffer.clear(); // Clear but keep the internal allocation.
do_some_work(i, &mut buffer);
buffer.last().map(|u| *u) // This is just an example value.
}
};
for i in ParallelIterator::new(|| (0..MAX), xform_ctor) {
match i {
Some(i) => println!("Got Some({})!", i),
None => println!("Got None!"),
}
}
}
Please see the documentation on the ParallelIterator struct for more details.
Licensed under either of
at your option.