Add rayon to Cargo.toml and use par_iter() to run collection operations in parallel across CPU cores.
Add the rayon crate to your Cargo.toml and use par_iter() to process collections in parallel.
[dependencies]
rayon = "1.10"
use rayon::prelude::*;
fn main() {
let v: Vec<i32> = (0..100).collect();
let sum: i32 = v.par_iter().sum();
println!("Sum: {}", sum);
}
This replaces standard iterators with parallel ones, automatically distributing work across available CPU cores.
Rayon is a tool that lets your Rust code run multiple tasks at the same time using all your computer's processor cores. Instead of processing a list of items one by one, it splits the work up so many items are handled simultaneously. Think of it like having a team of workers sort a pile of mail together instead of one person doing it alone.