Rayon-backed CPU executor service for Rust.
Qubit Rayon Executor adapts a dedicated Rayon thread pool to the Qubit
ExecutorService contract. It is intended for CPU-bound work where Rayon worker
scheduling is more appropriate than a general-purpose blocking queue.
The crate is separate from qubit-thread-pool and qubit-tokio-executor so
libraries can depend only on the execution model they need.
RayonExecutorServicefor managed CPU-bound task execution.RayonExecutorServiceBuilderfor configuring worker count, thread-name prefix, and stack size.TaskHandlefor callable results andRayonTaskHandlefor tracked status and cancellation.RayonExecutorServiceBuildErrorfor zero thread count, zero stack size, and Rayon build failures.- Shared
ExecutorService,SubmissionError, andStopReportre-exports for convenient imports. - Lifecycle behavior aligned with other Qubit executor services.
Rayon is optimized for CPU-bound parallel work. Use this crate when the workload primarily consumes CPU and should run on a dedicated Rayon pool. Avoid using it for long blocking IO operations, because blocking Rayon workers can reduce CPU parallelism for unrelated tasks.
If your task is synchronous and may block on IO, prefer qubit-thread-pool. If
your task is an async future or must integrate with Tokio, prefer
qubit-tokio-executor.
A successful submit means the service accepted a fire-and-forget runnable.
Use submit_callable for a result-only TaskHandle, or
submit_tracked / submit_tracked_callable when you need a RayonTaskHandle
with status and cancellation.
Queued tasks can be cancelled before Rayon starts running them. shutdown stops
accepting new tasks and allows accepted work to finish. stop stops
accepting new tasks and cancels work that has not started yet; already running
CPU work is not forcibly stopped. Cancelled callable and tracked handles report
TaskExecutionError::Cancelled.
use std::io;
use qubit_rayon_executor::{ExecutorService, RayonExecutorService};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let service = RayonExecutorService::builder()
.num_threads(4)
.thread_name_prefix("cpu-worker")
.build()?;
let handle = service.submit_callable(|| Ok::<usize, io::Error>((1..=10).sum()))?;
assert_eq!(handle.get()?, 55);
service.shutdown();
Ok(())
}Use RayonExecutorService for CPU-heavy computations that should be isolated in
a Rayon pool. Use qubit-thread-pool for general blocking OS-thread work. Use
qubit-tokio-executor for Tokio blocking tasks and async IO futures.
For application-level wiring across blocking, CPU-bound, Tokio blocking, and
async IO domains, use qubit-execution-services.
A minimal local run:
cargo test
cargo clippy --all-targets --all-features -- -D warningsTo mirror what continuous integration enforces, run the repository scripts from
the project root: ./align-ci.sh brings local tooling and configuration in line
with CI, then ./ci-check.sh runs the same checks the pipeline uses. For test
coverage, use ./coverage.sh to generate or open reports.
Issues and pull requests are welcome.
- Open an issue for bug reports, design questions, or larger feature proposals when it helps align on direction.
- Keep pull requests scoped to one behavior change, fix, or documentation update when practical.
- Before submitting, run
./align-ci.shand then./ci-check.shso your branch matches CI rules and passes the same checks as the pipeline. - Add or update tests when you change runtime behavior, and update this README or public rustdoc when user-visible API behavior changes.
- If you change cancellation or shutdown behavior, include tests for queued and already-running tasks where practical.
By contributing, you agree to license your contributions under the Apache License, Version 2.0, the same license as this project.
Copyright (c) 2026. Haixing Hu.
This project is licensed under the Apache License, Version 2.0. See the LICENSE file in the repository for the full text.
Haixing Hu — Qubit Co. Ltd.
| Repository | github.com/qubit-ltd/rs-rayon-executor |
| Documentation | docs.rs/qubit-rayon-executor |
| Crate | crates.io/crates/qubit-rayon-executor |