Executor abstractions and task-result primitives for Rust.
Qubit Executor provides the small common execution API used by the Qubit Rust concurrency crates. It separates lightweight execution strategies from managed executor services, and provides reusable task handles for implementations that need to publish task success, task failure, panic, or cancellation.
This crate deliberately avoids depending on Tokio, Rayon, or a concrete thread pool. Runtime-specific implementations live in smaller companion crates so libraries can depend only on the abstraction level they need.
- Strategy-level
Executortrait for executing one task and returning an implementation-specific result carrier. FutureExecutormarker trait for executors whose carrier is future-like.DirectExecutorfor deterministic same-thread execution.DelayExecutorfor delaying work before passing it to another executor.ThreadPerTaskExecutorfor spawning one OS thread per task without queue management.- Managed
ExecutorServicetrait withsubmit,submit_callable,shutdown,shutdown_now, and termination waiting. ThreadPerTaskExecutorServiceas a basic managed service implementation.TaskHandle,TaskCompletion,TaskExecutionError, andTaskResultfor sharing task completion semantics across crates.- Shared rejection and shutdown report types through
RejectedExecutionandShutdownReport.
Executor is a low-level execution strategy. It answers: “how should this one
task run, and what type represents the result?” A direct executor can return a
plain Result, while a thread-backed executor can return a TaskHandle.
ExecutorService is a managed service. It answers: “can this service accept a
task, track it, shut down, and eventually terminate?” A successful submit
means only that the service accepted the task. It does not mean the task has
started or completed successfully.
TaskHandle represents an accepted task. It supports blocking waits through
get, async waits through Future, completion checks through is_done, and
best-effort cancellation before the task starts.
Task execution errors are represented by TaskExecutionError:
Failed(E)means the task returned its own error value.Panickedmeans the task panicked while running.Cancelledmeans the task was cancelled before producing a value.
use std::io;
use qubit_executor::executor::{DirectExecutor, Executor};
let executor = DirectExecutor;
let value = executor.call(|| Ok::<usize, io::Error>(40 + 2))?;
assert_eq!(value, 42);
# Ok::<(), Box<dyn std::error::Error>>(())use std::io;
use qubit_executor::executor::{Executor, ThreadPerTaskExecutor};
let executor = ThreadPerTaskExecutor;
let handle = executor.call(|| Ok::<usize, io::Error>(40 + 2));
assert_eq!(handle.get()?, 42);
# Ok::<(), Box<dyn std::error::Error>>(())use std::io;
use qubit_executor::service::{ExecutorService, ThreadPerTaskExecutorService};
let service = ThreadPerTaskExecutorService::new();
let handle = service.submit_callable(|| Ok::<usize, io::Error>(40 + 2))?;
assert_eq!(handle.get()?, 42);
service.shutdown();
# Ok::<(), Box<dyn std::error::Error>>(())Use qubit-executor when you are defining APIs that should accept or return
executor abstractions without committing to a runtime. Use a runtime-specific
crate when you need a concrete implementation:
qubit-thread-poolprovides dynamic and fixed OS-thread pools.qubit-tokio-executorprovides Tokio-backed blocking and async IO services.qubit-rayon-executorprovides a Rayon-backed CPU-bound service.qubit-execution-servicesaggregates the concrete services for application-level wiring.
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.
By contributing, you agree to license your contributions under the Apache License, Version 2.0, the same license as this project.
Copyright © 2026 Haixing Hu, Qubit Co. Ltd.
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-executor |
| Documentation | docs.rs/qubit-executor |
| Crate | crates.io/crates/qubit-executor |