selectables
Lock-free Rust channels with a unified recv-arm select! model.
selectables provides a consistent selection interface across channel flavours,
with Crossbeam-style ergonomics and a small, focused API.
Highlights
- Lock-free fast paths for send and receive operations
- Unified
select!macro for recv arms (recv,default,default(duration)) - Bounded and unbounded MPMC/MPSC channels
- Rendezvous channel for synchronous handoff between sender and receiver
- Bounded broadcast with lag detection (
Lagged { skipped }) - Watch channel for latest-value subscriptions
- Oneshot channel for single-send/single-delivery
- Repeating timer receiver via
interval::interval()andinterval::interval_at()
When to use
Use selectables when you need:
- one selection model across different channel types
- predictable lock-free send/receive with optional blocking recv
- bounded broadcast with explicit lag reporting and recovery
- synchronous rendezvous semantics (zero-buffer handoff)
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Quick Start
use Duration;
use ;
let = ;
tx.send.unwrap;
// recv-arm selection with timeout fallback
select!
Channel types
| Module | Description |
|---|---|
unbounded_mpmc |
Lock-free unbounded multi-producer, multi-consumer queue |
bounded_mpmc |
Lock-free bounded multi-producer, multi-consumer ring buffer |
unbounded_mpsc |
Lock-free unbounded multi-producer, single-consumer queue |
bounded_mpsc |
Lock-free bounded multi-producer, single-consumer ring buffer |
rendezvous |
Zero-buffer synchronous handoff — sender blocks until a receiver is ready |
bounded_broadcast |
Bounded multi-producer, multi-receiver broadcast with per-receiver cursors |
watch |
Latest-value broadcast channel with versioned change notifications |
oneshot |
Single-send, single-delivery channel |
interval |
Repeating timer that yields Instant ticks on a fixed schedule |
Selection model
select! supports recv arms, send arms, and fallback arms:
use Duration;
use ;
let = ;
let = ;
tx_bounded.send.unwrap;
select!
Arm syntax at a glance:
| Arm | Fires when |
|---|---|
recv(rx) -> msg => { ... } |
a value is available on rx |
send(tx, val) -> res => { ... } |
tx has buffer space (or is disconnected) |
default => { ... } |
no arm is ready (non-blocking) |
default(duration) => { ... } |
no arm is ready within the timeout |
A low-level builder API is also available via Select and SelectedOperation.
Lag handling (bounded_broadcast)
Broadcast receivers return Lagged { skipped } when they fall behind a
bounded ring buffer. The cursor is automatically advanced to the oldest
surviving message, so the next call succeeds without any manual recovery.
use ;
let = ;
tx.send.unwrap;
match rx.recv
See the bounded_broadcast module for detailed lag recovery patterns.
Examples
Run the bundled demo:
The demo covers:
- Blocking and timed select usage
defaultanddefault(duration)branches- Bounded/unbounded MPMC and MPSC behaviour
- Watch updates and select integration
- Broadcast lag and recovery
- Oneshot usage and mixed-arm selection
For full API docs and module-level examples, see docs.rs/selectables.
Feature flags
debug-logs: enables internal trace logging via thelogcrate
License
Licensed under either of:
- MIT license
- Apache License, Version 2.0
at your option.
Repository and docs
- Repository: https://github.com/sria91/selectables
- Documentation: https://docs.rs/selectables