Parseq

Posted on

I’ve published my own parallel sequential iterator library for Rust, Parseq. Parseq provides an extension trait adding a map_parallel method to the standard iterator trait. It’s a drop-in-replacement for the standard map method.

use std::time::Duration;
use parseq::ParallelIterator;

let mut iter = (0..3)
  .into_iter()
  .map_parallel(|i| {
    // Insert heavy computation here ...
    std::thread::sleep(Duration::from_millis((i % 3) * 10));
    i
  });

assert_eq!(iter.next(), Some(0));
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), None);

See the repository for a real world example, and docs.io for the documentation.

Parseq is of course not the first crate providing a parallel map function for iterators. But I think it comes with a unique set of features:

In contrast, Rayon, the de-facto standard solution for Rust, doesn’t preserve the order of the original iterator. Pariter, a good sequential alternative addressing this exact issue, doesn’t support infinite iterators; though it provides more features than Parseq.

Therefore, I invite you to give Parseq a try, and send me some feedback.