5 releases (1 stable)
1.0.0 | Jan 8, 2024 |
---|---|
0.4.0 | Jan 7, 2024 |
0.3.0 | Jan 7, 2024 |
0.2.0 | Jan 7, 2024 |
0.1.0 | Jan 7, 2024 |
#2104 in Algorithms
33 downloads per month
7KB
90 lines
River Ring Buffer
A simple ring buffer implemented in Rust.
A ring buffer is a high performant data structure that is great for buffering streams of data.
My motivation for building this was to understand ring buffers as they're used extensively in new Linux Kernel feature such as eBPF and IO Uring.
Example usage
use river_ring_buffer::RingBuffer;
fn main() -> Result<(), &'static str> {
let mut buffer = RingBuffer::new(3);
buffer.put(1)?;
buffer.put(2)?;
buffer.put(3)?;
buffer.read(); // Returns Some(1)
}
An error is returned when the buffer is full.
use river_ring_buffer::RingBuffer;
fn main() -> Result<(), &'static str> {
let mut buffer = RingBuffer::new(3);
buffer.put(1)?;
buffer.put(2)?;
buffer.put(3)?;
buffer.put(4)?; // Returns Err(BufferFullError)
}