cargo.toml
[dependencies]
rayon = "1.10.0"
basic rayon usage
extern crate rayon;
use rayon::prelude::*;
rayon::prelude::*
is imported to access the
parallel iterator methods like par_iter, which converts a regular iterator to a parallel iterator.fn main() {
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let sum: i32 = arr.par_iter().sum();
println!("Sum of array: {}", sum);
}
sum()
method is automatically executed in parallel across multiple threads available on the system.