Trait ringbuffer::RingBufferRead
source · 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§
Provided Methods§
sourcefn drain(&mut self) -> RingBufferDrainingIterator<'_, T, Self>
fn drain(&mut self) -> RingBufferDrainingIterator<'_, T, Self>
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);