rt-ring 0.1.0

Lock-free SPSC ring buffer with overwrite-oldest semantics for real-time applications
Documentation
  • Coverage
  • 92.86%
    13 out of 14 items documented10 out of 13 items with examples
  • Size
  • Source code size: 83.43 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.61 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • hasanzakeri/rt-ring
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hasanzakeri

rt-ring

Lock-free SPSC (single-producer, single-consumer) ring buffer that overwrites the oldest data when full — designed for real-time audio and similar domains where freshness matters more than completeness.

Key Properties

  • Overwrite-oldest semantics: when the buffer is full, new writes discard the oldest sample instead of failing
  • Lock-free, real-time safe: no allocations, locks, or IO in the hot path
  • Safe Rust API: no unsafe code
  • Zero runtime dependencies

Usage

use rt_ring::{new, Producer, Consumer};

let (producer, consumer) = rt_ring::new(1024);

// Producer side (e.g., audio input callback)
producer.push(0.5);
producer.push_slice(&[0.1, 0.2, 0.3]);

// Consumer side (e.g., processing thread)
while let Some(sample) = consumer.pop() {
    // process sample
}

// Check how many samples were overwritten
println!("overwrites: {}", consumer.overwrite_count());

Semantics

  • FIFO when not full: if the consumer keeps up, samples arrive in exact push order with no gaps
  • Overwrite-oldest when full: the producer never blocks; it discards the oldest unread sample to make room
  • Monotonic with gaps: popped values are always in push order, but consecutive values may skip by up to capacity samples when overwrites occur
  • Accounting invariant: overwrite_count() + popped == pushed — always, in every interleaving
  • SPSC only: exactly one producer thread and one consumer thread; violating this is undefined behavior at the application level (no panic, just wrong results)
  • Capacity is a power of two: the requested capacity is rounded up, enabling fast modular indexing

Features

  • Overwrite counter tracks how many samples were dropped
  • Bulk push_slice / pop_slice operations
  • available() to query current buffer occupancy
  • Capacity automatically rounds up to the next power of two

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.