Use the par_iter() method from the rayon crate to automatically parallelize iteration over collections using multiple CPU cores.
Use the par_iter() method on a collection to process items in parallel across multiple threads.
use rayon::prelude::*;
let numbers: Vec<i32> = (1..100).collect();
let sum: i32 = numbers.par_iter().sum();
This spawns a thread pool automatically and distributes the iteration work across available CPU cores.
Rayon lets you run code on multiple CPU cores at the same time without writing complex thread management code. Think of it like hiring a team of workers to sort a pile of mail instead of doing it alone; they split the pile and work simultaneously to finish faster. You simply tell Rayon to process your data, and it handles the parallel execution for you.