ruffer 1.0.3

A simple overwriting ring buffer library written in Rust.
Documentation
  • Coverage
  • 91.67%
    11 out of 12 items documented1 out of 12 items with examples
  • Size
  • Source code size: 30.41 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 372.34 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • PrintPractical/ruffer
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • PrintPractical

ruffer 1.0.3

R[ing B]uffer is a simple overwriting ring buffer implementation. A RingBuffer allocates it's memory once at creation on the heap. The RingBuffer implements std::io::Read and std::io::Write for interacting with the buffer. Any size buffer can be written to the RingBuffer, just note that only the capacity of the RingBuffer will be retained. Reading data from the buffer will move the tail index, so the read data is essentially dropped. If one wants to get a copy of the data on the form of a vector, a helper function are available to easily acquire one.

Features

  • sync - A Sync implementation of the RingBuffer.

Usage

Create a new RingBuffer with a specific capacity

use ruffer::RingBuffer;

let buffer = RingBuffer::with_capacity(1024);

Write data to the buffer

use ruffer::RingBuffer;
use std::io::Write;

let mut buffer = RingBuffer::with_capacity(1024);
let write_data = "Test data buffer".as_bytes();
match buffer.write(&write_data) {
  Ok(bytes) => {
    println!("wrote {} bytes to buffer", bytes);
  }
  Err(e) => {
    println!("{}", e);
  }
}

Read data from the buffer

use ruffer::RingBuffer;
use std::io::Read;

let mut buffer = RingBuffer::with_capacity(1024);
// ... use ringbuffer ...
let read_data = &mut [0u8; 32];
match buffer.read(read_data) {
  Ok(bytes) => {
    println!("read {} bytes from buffer", bytes);
  }
  Err(e) => {
    println!("{}", e);
  }
}

Release Notes

v1.0.3

  • Added the ability to turn overwriting off. This may be helpful for Producer/Consumer type use cases.

v1.0.2 and Previous

  • These were the initial commits of Ruffer. I messed up some stuff around the docs etc, so my bad...

License

Apache-2.0