pub trait RingBufferRead<T>: RingBuffer<T> {
    fn dequeue(&mut self) -> Option<T>;
    fn skip(&mut self);

    fn drain(&mut self) -> RingBufferDrainingIterator<'_, T, Self> { ... }
}
Expand description

Defines behaviour for ringbuffers which allow for reading from the start of them (as a queue). For arbitrary buffer access however, RingBufferExt is necessary.

Required methods

dequeues the top item off the ringbuffer, and moves this item out.

dequeues the top item off the queue, but does not return it. Instead it is dropped. If the ringbuffer is empty, this function is a nop.

Provided methods

Returns an iterator over the elements in the ringbuffer, dequeueing elements as they are iterated over.

use ringbuffer::{AllocRingBuffer, RingBufferWrite, RingBufferRead, RingBuffer};

let mut rb = AllocRingBuffer::with_capacity(16);
for i in 0..8 {
    rb.push(i);
}

assert_eq!(rb.len(), 8);

for i in rb.drain() {
    // prints the numbers 0 through 8
    println!("{}", i);
}

// No elements remain
assert_eq!(rb.len(), 0);

Implementors