Bit-Masking Ring Buffer
A ring buffer implementation with cheap indexing written in Rust.
Note, this crate is only beneficial if your algorithm indexes elements one at a time and has buffer sizes that are always a power of two. If your algorithm instead reads chunks of data as slices or requires buffer sizes that are not a power of two, then check out my crate slice_ring_buf.
This crate has no consumer/producer logic, and is meant to be used for DSP or as a base for other data structures.
This crate can also be used without the standard library (#![no_std]).
Example
use ;
// Create a ring buffer with type u32. The data will be
// initialized with the given value (0 in this case).
// The actual length will be set to the next highest
// power of 2 if the given length is not already
// a power of 2.
let mut rb = new;
assert_eq!;
// Read/write to buffer by indexing with an `isize`.
rb = 0;
rb = 1;
rb = 2;
rb = 3;
// Cheaply wrap when reading/writing outside of bounds.
assert_eq!;
assert_eq!;
// Memcpy into slices at arbitrary `isize` indexes
// and length.
let mut read_buffer = ;
rb.read_into;
assert_eq!;
// Memcpy data from a slice into the ring buffer at
// arbitrary `isize` indexes. Earlier data will not be
// copied if it will be overwritten by newer data,
// avoiding unecessary memcpy's. The correct placement
// of the newer data will still be preserved.
rb.write_latest;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// Read/write by retrieving slices directly.
let = rb.as_slices_len;
assert_eq!;
assert_eq!;
// Aligned/stack data may also be used.
let mut stack_data = ;
let mut rb_ref = new;
rb_ref = 5;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// Linear interpolation is also provided (requires the
// `interpolation` feature which requires the standard
// library.)
let rb = from_vec;
assert!;