[][src]Trait ringbuffer::RingBuffer

pub trait RingBuffer<T: 'static>: Default + Index<isize, Output = T> + IndexMut<isize> + FromIterator<T> {
    fn len(&self) -> usize;
fn clear(&mut self);
fn capacity(&self) -> usize;
fn get(&self, index: isize) -> Option<&T>;
fn get_mut(&mut self, index: isize) -> Option<&mut T>;
fn get_absolute(&self, index: usize) -> Option<&T>;
fn get_absolute_mut(&mut self, index: usize) -> Option<&mut T>;
fn push(&mut self, value: T);
fn dequeue_ref(&mut self) -> Option<&T>;
fn skip(&mut self); fn is_empty(&self) -> bool { ... }
fn is_full(&self) -> bool { ... }
fn peek(&self) -> Option<&T> { ... }
fn back(&self) -> Option<&T> { ... }
fn front(&self) -> Option<&T> { ... }
fn back_mut(&mut self) -> Option<&mut T> { ... }
fn front_mut(&mut self) -> Option<&mut T> { ... }
fn iter(&self) -> RingBufferIterator<'_, T, Self> { ... }
fn iter_mut(&mut self) -> RingBufferMutIterator<'_, T, Self> { ... }
fn to_vec(&self) -> Vec<T>
    where
        T: Clone
, { ... }
fn contains(&self, elem: &T) -> bool
    where
        T: PartialEq
, { ... }
fn dequeue(&mut self) -> Option<T>
    where
        T: Clone
, { ... } }

RingBuffer is a trait defining the standard interface for all RingBuffer implementations (AllocRingBuffer, GenericRingBuffer, ConstGenericRingBuffer)

This trait is not object safe, so can't be used dynamically. However it is possible to define a generic function over types implementing RingBuffer.

Required methods

fn len(&self) -> usize

Returns the length of the internal buffer. This length grows up to the capacity and then stops growing. This is because when the length is reached, new items are appended at the start.

fn clear(&mut self)

Empties the buffer entirely. Sets the length to 0 but keeps the capacity allocated.

fn capacity(&self) -> usize

Returns the capacity of the buffer.

fn get(&self, index: isize) -> Option<&T>

Gets a value relative to the current index. 0 is the next index to be written to with push. -1 and down are the last elements pushed and 0 and up are the items that were pushed the longest ago.

fn get_mut(&mut self, index: isize) -> Option<&mut T>

Gets a value relative to the current index mutably. 0 is the next index to be written to with push. -1 and down are the last elements pushed and 0 and up are the items that were pushed the longest ago.

fn get_absolute(&self, index: usize) -> Option<&T>

Gets a value relative to the start of the array (rarely useful, usually you want Self::get)

fn get_absolute_mut(&mut self, index: usize) -> Option<&mut T>

Gets a value mutably relative to the start of the array (rarely useful, usually you want Self::get_mut)

fn push(&mut self, value: T)

Pushes a value onto the buffer. Cycles around if capacity is reached.

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

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

Pops 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 is_empty(&self) -> bool

Returns true if the buffer is entirely empty. This is currently only true when nothing has ever been pushed, or when the Self::clear function is called. This might change when the pop function is added with issue #21

fn is_full(&self) -> bool

Returns true when the length of the ringbuffer equals the capacity. This happens whenever more elements than capacity have been pushed to the buffer.

fn peek(&self) -> Option<&T>

Returns the value at the current index. This is the value that will be overwritten by the next push and also the value pushed the longest ago. (alias of Self::front)

fn back(&self) -> Option<&T>

Returns the value at the back of the queue. This is the item that was pushed most recently.

fn front(&self) -> Option<&T>

Returns the value at the back of the queue. This is the value that will be overwritten by the next push and also the value pushed the longest ago. (alias of peek)

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

Returns a mutable reference to the value at the back of the queue. This is the item that was pushed most recently.

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

Returns a mutable reference to the value at the back of the queue. This is the value that will be overwritten by the next push. (alias of peek)

fn iter(&self) -> RingBufferIterator<'_, T, Self>

Creates an iterator over the buffer starting from the latest push. Creates an iterator over the buffer starting from the item pushed the longest ago, and ending at the element most recently pushed.

fn iter_mut(&mut self) -> RingBufferMutIterator<'_, T, Self>

Creates a mutable iterator over the buffer starting from the latest push. Creates a mutable iterator over the buffer starting from the item pushed the longest ago, and ending at the element most recently pushed.

fn to_vec(&self) -> Vec<T> where
    T: Clone

Converts the buffer to a vector. This Copies all elements in the ringbuffer.

fn contains(&self, elem: &T) -> bool where
    T: PartialEq

Returns true if elem is in the ringbuffer.

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

Dequeues the top item off the ringbuffer and returns an owned version. See the pop_ref docs

Loading content...

Implementors

impl<T: 'static> RingBuffer<T> for AllocRingBuffer<T>[src]

impl<T: 'static, Cap: ArrayLength<MaybeUninit<T>>> RingBuffer<T> for GenericRingBuffer<T, Cap>[src]

Loading content...