Trait ringbuffer::RingBufferRead[][src]

pub trait RingBufferRead<T>: RingBuffer<T> {
    fn dequeue_ref(&mut self) -> Option<&T>;
fn skip(&mut self); fn dequeue(&mut self) -> Option<T>
    where
        T: Clone
, { ... }
fn drain(&mut self) -> RingBufferDrainingIterator<'_, T, Self>
    where
        T: Clone
, { ... } }

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

fn dequeue_ref(&mut self) -> Option<&T>[src]

dequeues the top item off the ringbuffer. Returns a reference to the item. This means that lifetimes will be problematic because as long as this reference exists, you can not push to the queue. To solve this, use the dequeue method. This requires the item to be clone. Easily moving out of the ringbuffer is sadly impossible.

Returns None when the ringbuffer is empty.

fn skip(&mut self)[src]

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.

Loading content...

Provided methods

fn dequeue(&mut self) -> Option<T> where
    T: Clone
[src]

dequeues the top item off the ringbuffer and returns a cloned version. See the dequeue_ref docs

fn drain(&mut self) -> RingBufferDrainingIterator<'_, T, Self> where
    T: Clone
[src]

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);
Loading content...

Implementors

impl<T> RingBufferRead<T> for AllocRingBuffer<T>[src]

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

Loading content...