Crate ringbuffer[−][src]
Ringbuffer
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. |
ConstGenericRingBuffer | Ringbuffer which uses const generics to allocate on the stack. |
All of these ringbuffers also implement the RingBuffer
trait for their shared API surface.
Usage
use ringbuffer::{AllocRingBuffer, RingBuffer, RingBufferExt, RingBufferWrite}; 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. |
License
Licensed under GNU Lesser General Public License v3.0
Structs
AllocRingBuffer | The |
ConstGenericRingBuffer | The |
Constants
RINGBUFFER_DEFAULT_CAPACITY | The capacity of a |
Traits
RingBuffer |
|
RingBufferExt | Defines behaviour for ringbuffers which allow them to be used as a general purpose buffer. With this trait, arbitrary access of elements in the buffer is possible. |
RingBufferRead | Defines behaviour for ringbuffers which allow for reading from the start of them (as a queue).
For arbitrary buffer access however, |
RingBufferWrite | Defines behaviour for ringbuffers which allow for writing to the end of them (as a queue).
For arbitrary buffer access however, |