# Bufferring: Ring buffers for Rust
A ring buffer is a fixed-size queue of items, where new items replace older ones
when a fixed limit (the buffer's capacity) is hit. This crate provides a safe
interface for ring buffers, along with some implementations of this interface.
**WARNING**: This crate is not ready for use. It contains a significant amount
of `unsafe` code, but is currently completely untested.
## Usage
```rust
use core::num::NonZeroUsize;
use bufferring::{
RingBuffer, MaskingBuffer,
storage::{Storage, HeapStorage},
};
// Create a masking-based ring buffer using heap-allocated storage.
let capacity = NonZeroUsize::new(8).unwrap();
let storage = HeapStorage::with_capacity(capacity);
let mut buffer = MaskingBuffer::new(storage).unwrap();
// Push some elements into the buffer.
for item in 0 .. 14 {
// Drop removed items immediately.
let _ = buffer.enqueue(item);
}
// See what elements are in the buffer.
println!("{:?}", buffer);
assert!(buffer.is_full());
assert!(buffer.iter().copied().eq(6 .. 14));
// Remove those elements from the buffer.
for item in 6 .. 14 {
assert_eq!(buffer.dequeue(), Some(item));
}
assert!(buffer.is_empty());
```
## Origin
This crate is heavily inspired by [ringbuffer][]; some of the changes here have
been ported over, but the interface exposed is incompatibly different.
[ringbuffer]: https://github.com/NULLx76/ringbuffer