Rotating Buffer (RotBuf)
A dynamically sized Queue implementation using the Bytes
crate's BufferMut. The RotatingBuffer allows user to store sequenced bytes in a bytes buffer without needing to move data down the buffer.
To get started, you can easily create a RotatingBuffer
knowing only the maximum size. Resizing is not currently implemented but may be implemented in the future, so choose your size wisely.
use RotatingBuffer;
Enqueueing and Dequeueing
The simplest way to use the RotatingBuffer
is to treat it like a queue, enqueing and dequeing one byte at a time.
enqueue
is very easy, just provide it with any u8
(best representation for a singular byte).
dequeue
returns an Option
, containing either the front most byte in Some, or, if empty, None.
rb = new;
rb.enqueue?
match rb.dequeue
enqueue
in most cases will return an empty [Ok] to signify it was successful. If it reaches the capacity of the RotatingBuffer, it will return an Err with a RotatingBufferAtCapacity.
match rb.enqueue
The RotatingBufferAtCapacity is an Error, but you can reclaim the value you provided by using the reclaim
fn
match rb.enqueue