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

    // Provided method
    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§

source

fn dequeue(&mut self) -> Option<T>

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

source

fn skip(&mut self)

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§

source

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);

Implementors§

source§

impl<T> RingBufferRead<T> for GrowableAllocRingBuffer<T>

source§

impl<T, SIZE: RingbufferSize> RingBufferRead<T> for AllocRingBuffer<T, SIZE>

source§

impl<T, const CAP: usize> RingBufferRead<T> for ConstGenericRingBuffer<T, CAP>