river-ring-buffer

Crates.ioriver-ring-buffer
lib.rsriver-ring-buffer
version1.0.0
sourcesrc
created_at2024-01-07 09:47:46.630841
updated_at2024-01-08 13:51:30.196679
descriptionA simple ring buffer implementation
homepage
repositoryhttps://github.com/RiverPhillips/river-ring-buffer
max_upload_size
id1091651
size18,056
River (RiverPhillips)

documentation

README

River Ring Buffer

Crates.io Version docs.rs (with version) GitHub Actions Workflow Status Crates.io License

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)   
}
Commit count: 0

cargo fmt