Skip to main content

Module ring

Module ring 

Source
Expand description

Fixed-size, stack-allocated ring buffer — no heap, no alloc, no atomics.

RingBuf is a single-owner (&mut self) ring that overwrites the oldest element when full. It requires T: Copy + Default and is ideal for sample windows, local event logs, and anywhere a simple circular buffer is needed without cross-thread sharing.

For a lock-free SPSC ring with sequence tracking, see crate::SeqRing. For a lock-free SPSC ring with backpressure, see crate::EventBuf.

§Example

use ph_eventing::RingBuf;

let mut r = RingBuf::<u32, 4>::new();
r.push(10);
r.push(20);
assert_eq!(r.latest(), Some(20));
assert_eq!(r.get(0), Some(10)); // oldest

Structs§

RingBuf
A ring buffer of N elements stored entirely on the stack.
RingIter
Iterator over RingBuf elements from oldest to newest.