crossbeam-ring-channel
A small Rust crate that adds a ring-buffer channel alongside crossbeam-channel, plus a Select wrapper that can mix ring receivers with standard crossbeam-channel send/recv operations.
What it provides
ring_bounded(capacity): a bounded, ring-buffer channel.RingSender/RingReceiver: sender/receiver halves with familiar methods.Select+select!/select_biased!: crossbeam-style selection that works with ring receivers and crossbeam-channel send/recv operations.
Semantics
- The ring channel is bounded and non-blocking on send.
- When full,
sendevicts the oldest item in the buffer to make room for the new one. recvblocks until an item is available or all senders are dropped.
Installation
Add to your Cargo.toml:
[]
= "0.1"
= "0.5" # needed if you use crossbeam-channel receivers/senders in Select
Usage
Basic ring channel:
use ring_bounded;
let = ring_bounded;
// Sends never block; the oldest item is dropped when full.
tx.send.unwrap;
tx.send.unwrap;
tx.send.unwrap;
assert_eq!;
assert_eq!;
Selecting over ring receivers and crossbeam-channel receivers:
use unbounded;
use ;
let = ;
let = ;
ring_tx.send.unwrap;
tx.send.unwrap;
let mut sel = new;
let ring_idx = sel.recv;
let cb_idx = sel.recv;
let oper = sel.select;
match oper.index
Macro selection:
use ;
let = ;
tx.send.unwrap;
select!
API overview
ring_bounded(size)RingSender<T>/RingReceiver<T>send,recv,try_recv,recv_timeoutlen,capacity,is_empty,is_full,same_channel
SelectandSelectedOperation- Macros:
select!,select_biased!