rx-rust
Reactive Extensions for Rust. rx-rust offers a comprehensive, zero-unsafe toolkit for composing asynchronous and event-driven programs by chaining observables and operators in a declarative style inspired by ReactiveX.
Installation
rx-rust is a regular Cargo library crate. Add it to your project like any other dependency:
[]
= { = "the_latest_version", = ["tokio-scheduler"] } # Use tokio runtime
= { = "the_latest_version", = ["async-std-scheduler"] } # Use async-std runtime
= { = "the_latest_version", = ["thread-pool-scheduler"] } # Use futures thread pool
= { = "the_latest_version", = ["tokio-scheduler"] } # Use futures local pool
Feature Flags
| Feature | Description | Pulls in |
|---|---|---|
multi-threaded (default) |
Core operators with Send-friendly observables. |
– |
single-threaded |
Core operators optimised for single-threaded use. | – |
local-pool-scheduler |
Scheduler backed by futures local pool (enable for Interval, Timer, etc.). |
single-threaded, futures, async-io |
thread-pool-scheduler |
Scheduler backed by futures thread pool. |
futures/thread-pool, async-io |
tokio-scheduler |
Scheduler integration for Tokio runtimes. | futures, tokio/rt, tokio/time |
async-std-scheduler |
Scheduler based on async-std. | futures, async-std |
Quick Start
Build pipelines by combining operators from ObservableExt and subscribe with callbacks or custom observers.
use ObservableExt;
use Termination;
use Range;
new
.map
.filter
.subscribe_with_callback;
Scheduling Example
Time-based operators require a scheduler. The example below uses Tokio; similar code works with the other scheduler features.
async
Project Layout
src/observable– Core observable traits and theObservableExtextension trait that wires in every operator.src/operators– Operator implementations grouped by category (creating,transforming,combining,utility, and more) to mirror ReactiveX terminology.src/subject– Subjects bridging observers and observables for multicast workflows.src/scheduler– Scheduler abstractions and adapters for popular async executors.tests/– Exhaustive conformance tests covering each operator; great as executable documentation.