| Crates.io | ruffer |
| lib.rs | ruffer |
| version | 1.0.3 |
| created_at | 2025-01-01 21:53:54.469661+00 |
| updated_at | 2025-01-06 22:18:28.275532+00 |
| description | A simple overwriting ring buffer library written in Rust. |
| homepage | |
| repository | https://github.com/PrintPractical/ruffer |
| max_upload_size | |
| id | 1501103 |
| size | 30,411 |
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.
sync - A Sync implementation of the RingBuffer.use ruffer::RingBuffer;
let buffer = RingBuffer::with_capacity(1024);
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);
}
}
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);
}
}