pub struct RotatingBuffer { /* private fields */ }Expand description
The RotatingBuffer is a queue implementation wrapping a BytesMut.
RotatingBuffer::enqueue and RotatingBuffer::dequeue will not require memory to be shifted.
Implementations§
Source§impl RotatingBuffer
impl RotatingBuffer
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether or not the RotatingBuffer is empty
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total capacity. This is the number of elements we can enqueue (without dequeueing) before we can no longer enqueue anymore elements. Once we reach this capacity, you must dequeue in order to fit into the RotatingBuffer without resizing.
Sourcepub fn peek_pos(&self, pos: usize) -> Option<u8>
pub fn peek_pos(&self, pos: usize) -> Option<u8>
Peek the value stored at a given position.
Note: pos is the position in the queue, not necessarily the index in the buffer,
and starts at 0 where 0 represents the head of the queue.
Sourcepub fn peek(&self) -> Option<u8>
pub fn peek(&self) -> Option<u8>
Peeks the first value in the queue. Returns None if the queue is empty.
This method should be preferred over calling RotatingBuffer::peek_pos at position 0.
Sourcepub fn peek_last(&self) -> Option<u8>
pub fn peek_last(&self) -> Option<u8>
Peeks the last value in the queue. Returns None if the queue is empty.
This should be preferred over calling RotatingBuffer::peek_pos at position (last position)
Sourcepub fn dequeue(&mut self) -> Option<u8>
pub fn dequeue(&mut self) -> Option<u8>
Returns the front-most value from the Queue in a Some. If the RotatingBuffer is empty, we will return a None.
This should be fairly cheap to run, as no memory in the buffer is altered. Once an item is dequeued, every sequential item’s position is one less than it was before.
Sourcepub fn at_capacity(&self) -> bool
pub fn at_capacity(&self) -> bool
Returns a bool representing whether the RotatingBuffer is at capacity. This means that enqueueing another value will cause an Err.
Sourcepub fn enqueue(&mut self, value: u8) -> Result<(), RotatingBufferAtCapacity>
pub fn enqueue(&mut self, value: u8) -> Result<(), RotatingBufferAtCapacity>
Enqueues an item into the RotatingBuffer. Returns an Err with a RotatingBufferAtCapacity if at capacity.
Enqueueing should be fairly cheap, as we initialize the internal buffer with the maximum size given in the constructor, so we will always be either replacing a pre-existing and already dequeued value, or we will be placing a value into already allocated memory.