A fixed-size circular buffer written in Rust. https://github.com/NULLx76/ringbuffer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Victor 9340d321b3
Merge pull request #29 from NULLx76/better_buffer
1 year ago
.github/workflows Add codecov token 1 year ago
benches Fix minor things 1 year ago
src improved speed ~50% by inlining and added benchmarks 1 year ago
.drone.yml remove codecov from drone so no conflicts happen 1 year ago
.gitignore first benches 1 year ago
.gitlab-ci.yml Add .gitlab-ci.yml 2 years ago
Cargo.toml Fix minor things 1 year ago
LICENSE Add LICENSE 2 years ago
README.md remove references to `generic_uninit` 1 year ago

README.md

Ringbuffer

Drone (self-hosted) Codecov Docs.rs Crates.io

The ringbuffer crate provides safe fixed size circular buffers (ringbuffers) in rust.

Implementations for three kinds of ringbuffers, with a mostly similar API are provided:

type description
AllocRingBuffer Ringbuffer allocated on the heap at runtime. This ringbuffer is still fixed size and requires alloc.
GenericRingBuffer Ringbuffer allocated on the stack. This is done using the typenum crate to provide a const-generic like interface without needing nightly
ConstGenericRingBuffer Ringbuffer which uses const generics to allocate on the stack. This type is feature-gated behind const_generics and only works in nightly rust.

All of these ringbuffers also implement the RingBuffer trait for their shared API surface.

Usage

use ringbuffer::{AllocRingBuffer, RingBuffer};
fn main() {
    let mut buffer = AllocRingBuffer::with_capacity(2);

    // First entry of the buffer is now 5.
    buffer.push(5);

    // The last item we pushed is 5
    assert_eq!(buffer.get(-1), Some(&5));

    // Second entry is now 42.
    buffer.push(42);
    assert_eq!(buffer.peek(), Some(&5));
    assert!(buffer.is_full());

    // Because capacity is reached the next push will be the first item of the buffer.
    buffer.push(1);
    assert_eq!(buffer.to_vec(), vec![42, 1]);
}

Features

name default description
alloc Disable this feature to remove the dependency on alloc. Useful for kernels.
const_generics Enables the ConstGenericRingBuffer. This requires nightly.
generic_array Disable this feature to remove the generic_array and typenum dependencies (and disables GenericRingBuffer).

License

Licensed under GNU Lesser General Public License v3.0