How rayon-rs/rayon works
High-level components
• Rayon API crate (“rayon” in the top-level src/)
• Core runtime crate (rayon-core/)
• Demo application crate (rayon-demo/)
• CI/tooling crates (ci/alt-core/, ci/highlander/)
• Build & test orchestrator (Cargo + GitHub Actions)
• External environment: OS threads, target platforms (native, WASM)
Relationships and data flow
• The Demo app (rayon-demo) depends on the Rayon API crate.
• The API crate (top-level) exports the public par_iter, join, scope, etc., and depends on rayon-core.
• rayon-core implements the work-stealing thread pool, job scheduler, task registry, latches, etc., and issues OS-thread calls.
• CI crates (alt-core, highlander) are alternate or supplementary build/test harnesses that also depend on rayon-core or provide custom build logic.
• GitHub Actions workflows invoke cargo build, cargo test, run the CI crates, and deploy documentation.
• The WASM adapter (not in tree but documented) would sit alongside the core runtime, routing threading calls to a JS thread pool or fall back to sequential.
Architectural patterns
• Layered
– Presentation/API layer (public prelude, iterator adapters in src/iter, src/collections)
– Runtime layer (rayon-core thread_pool, scheduler, job, registry modules)
– OS layer (actual threads, synchronization primitives)
• Modular: each parallel operator (map, filter, join, scope) is its own module under src/iter or rayon-core/src
• Work-stealing scheduler pattern in rayon-core/src/thread_pool
• Zero-cost abstraction: most of the API is compile-time plumbing, falling back to no-op or sequential execution on unsupported targets.
Relevant technologies & tools
• Rust & Cargo (crate-based compilation, workspace)
• GitHub Actions CI (.github/workflows/*.yaml)
• Shell scripts (ci/highlander.sh, scripts/analyze.sh)
• Platform adapters (Unix vs. Windows in rayon-demo/src/cpu_time)
• Testing harness (tests/ directories in each crate)