Bufferring: Ring buffers for Rust
A ring buffer is a fixed-size queue of items, where new items replace older ones when a fixed limit (the buffer's capacity) is hit. This crate provides a safe interface for ring buffers, along with some implementations of this interface.
WARNING: This crate is not ready for use. It contains a significant amount
of unsafe
code, but is currently completely untested.
Usage
use NonZeroUsize;
use ;
// Create a masking-based ring buffer using heap-allocated storage.
let capacity = new.unwrap;
let storage = with_capacity;
let mut buffer = new.unwrap;
// Push some elements into the buffer.
for item in 0 .. 14
// See what elements are in the buffer.
println!;
assert!;
assert!;
// Remove those elements from the buffer.
for item in 6 .. 14
assert!;
Origin
This crate is heavily inspired by ringbuffer; some of the changes here have been ported over, but the interface exposed is incompatibly different.