Crates.io | river-ring-buffer |
lib.rs | river-ring-buffer |
version | 1.0.0 |
source | src |
created_at | 2024-01-07 09:47:46.630841 |
updated_at | 2024-01-08 13:51:30.196679 |
description | A simple ring buffer implementation |
homepage | |
repository | https://github.com/RiverPhillips/river-ring-buffer |
max_upload_size | |
id | 1091651 |
size | 18,056 |
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.
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)
}