Rayon
Data-parallelism library for Rust that turns sequential iterators into parallel iterators safely.
Official Documentation ↗rayon 1.10 / Rust 1.63+. Check the official docs for the latest API surface.Installation
cargo add rayonMethods
No methods match this filter.
Overview
Rayon adds parallel iterators to Rust collections. Sequential chainable iterator methods have parallel counterparts, and the compiler enforces the thread-safety bounds.
Core Methods
Import the prelude and transform sequential iterators into parallel ones with into_par_iter or par_iter, then use map, filter, reduce and collect. Parallel sort and join help with slices and task splitting.
Usage Notes
Use it for CPU-bound data processing, keep per-item work meaningful to amortize overhead, and prefer immutable data or explicit synchronization. Profile before and after parallelizing.
Common Pitfalls
Shared mutable state without synchronization will not compile and, if forced with unsafe, races. Tiny tasks lose more to overhead than they gain. Nested pools can oversubscribe threads if configured carelessly.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://docs.rs/rayon/latest/rayon/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:05.525Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Thread Pool Build Error Error when initializing a thread pool. (https://docs.rs/rayon/latest/rayon/)
FAQ
- When should I not use Rayon?
- For very small workloads the scheduling overhead can outweigh the gain. Measure first, and keep parallelism for CPU-bound work; I/O-bound concurrency belongs to async runtimes.
- How is thread safety enforced?
- Rayon requires the item and closure to satisfy Send and Sync, so data races are prevented at compile time. Shared mutation needs synchronization such as a mutex or atomics.
- Can I control the thread pool?
- Yes. You can build a custom ThreadPool and install it, or use the global pool, and tune thread counts for the workload. Nested parallel work shares the pool by default.
Report a problem with this API docOpens a pre-filled issue on GitHub.