How to use rayon for parallel iteration

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.