rayon – parallel iterators

In the previous section, we built an iterator over Rust integer types. The essential computation of each next call was small—some branch checks, and possibly a negation or an addition. If we were to try to parallelize this, we'd drown out any potential performance bump with the time it takes to allocate a new thread from the operating systems. No matter how fast that becomes, it will still be slower than an addition. But, say we've gone all-in on writing in iteration style and do have computations that would benefit from being run in parallel. How do you make std::iter::Iterator parallel?

You use rayon.

The rayon crate is a data-parallelism library for Rust. That is, it extends Rust's basic Iterator concept to include ...

Get Hands-On Concurrency with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.