explaingit

rayon-rs/rayon

12,990RustAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

Rayon is a Rust library that lets you run code in parallel across CPU cores by changing a single word in your iterator calls, while Rust's type system prevents data race bugs at compile time.

Mindmap

mindmap
  root((rayon))
    What it does
      Parallel iteration
      Compile-time safety
      Thread pools
    Tech Stack
      Rust
      WebAssembly
    Use Cases
      Data processing
      Simulations
      Server workloads
    Audience
      Rust developers
      Performance engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Speed up data processing pipelines by switching from sequential to parallel iterators with a one-word change.

USE CASE 2

Build multithreaded simulations or batch algorithms without risking unpredictable data race bugs.

USE CASE 3

Create isolated thread pools to control how much CPU a specific part of your app can use.

Tech stack

RustWebAssembly

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercial use, under either the MIT or Apache 2.0 license, whichever you prefer.

In plain English

Rayon is a library for the Rust programming language that makes it easier to run code in parallel across multiple CPU cores. The core idea is that you can take code that processes a list of items one at a time and, with a small change, make it process many items at the same time. In many cases the change is as simple as replacing one word in your code: where you previously wrote something like "iter", you write "par_iter" instead, and Rayon handles the rest. The library is designed to avoid a common category of bugs that plague parallel programs. When multiple parts of a program run at the same time and try to read and write the same data without coordination, the results can be unpredictable and hard to reproduce. Rayon's design works with Rust's type system to prevent this class of problem at compile time. If your code compiles with Rayon, the parallel version is expected to produce the same results as the original sequential version, with a possible exception when your code has side effects that depend on order, such as writing to a file. Beyond the simple parallel iterator pattern, Rayon provides lower-level tools for splitting work manually and controlling how tasks are grouped. It also lets you create separate thread pools instead of using the shared default one, which can matter when you need to isolate work or control resource usage more carefully. Rayon works in WebAssembly environments as well. By default it falls back to single-threaded behavior there, so existing code compiles without changes. If you need real multithreading in a WebAssembly context, the README points to a separate adapter project that enables it. The project is open source and dual-licensed under the MIT and Apache 2.0 licenses. A demo directory in the repository includes runnable examples, including a visualization of a physics simulation where you can switch between sequential and parallel execution to observe the difference in speed.

Copy-paste prompts

Prompt 1
Show me how to convert a sequential Rust iterator using .iter() into a parallel one using Rayon's .par_iter(), with a before-and-after example.
Prompt 2
Write a Rust function using Rayon that processes a large Vec<f64> in parallel to compute the sum.
Prompt 3
How do I create a custom Rayon thread pool and run tasks inside it instead of using the global pool?
Prompt 4
Give me a Rayon example that splits work manually using rayon::join() for two independent tasks.
Prompt 5
How does Rayon prevent data races, what Rust traits enforce this at compile time?
Open on GitHub → Explain another repo

← rayon-rs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.