[][src]Struct ringbuffer::RingBuffer

pub struct RingBuffer<T> { /* fields omitted */ }

The RingBuffer struct.

Example

use ringbuffer::RingBuffer;

let mut buffer = RingBuffer::with_capacity(2);

// First entry of the buffer is now 5.
buffer.push(5);

assert_eq!(buffer[0], 5);

// Second entry is now 42.
buffer.push(42);

// Because capacity is reached the next push will be the first item of the buffer.
buffer.push(1);
assert_eq!(buffer[0], 1);

Methods

impl<T> RingBuffer<T>[src]

pub fn with_capacity(cap: usize) -> Self[src]

Creates a RingBuffer with a certain capacity.

pub fn new() -> Self[src]

Creates a RingBuffer with a capacity of RINGBUFFER_DEFAULT_CAPACITY.

pub fn len(&self) -> usize[src]

Returns the length of the internal buffer.

pub fn is_empty(&self) -> bool[src]

Returns true if the buffer is empty, some value between 0 and capacity.

pub fn clear(&mut self)[src]

Empties the buffer.

pub fn capacity(&self) -> usize[src]

Returns the capacity of the buffer.

pub fn push(&mut self, e: T)[src]

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

pub fn peek(&self) -> Option<&T>[src]

Returns the value at the current index. This is the value that will be overwritten by the next push.

pub fn iter(&self) -> Iter<T>[src]

Creates an iterator over the buffer starting from the latest push.

pub fn iter_mut(&mut self) -> IterMut<T>[src]

Creates a mutable iterator over the buffer starting from the latest push.

pub fn to_vec(&self) -> Vec<T> where
    T: Copy
[src]

Converts the buffer to an vector.

Trait Implementations

impl<T: Debug> Debug for RingBuffer<T>[src]

impl<T> Default for RingBuffer<T>[src]

fn default() -> Self[src]

Creates a buffer with a capacity of RINGBUFFER_DEFAULT_CAPACITY.

impl<T> Index<usize> for RingBuffer<T>[src]

type Output = T

The returned type after indexing.

impl<T> IndexMut<usize> for RingBuffer<T>[src]

impl<T: PartialEq> PartialEq<RingBuffer<T>> for RingBuffer<T>[src]

impl<T> StructuralPartialEq for RingBuffer<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for RingBuffer<T> where
    T: RefUnwindSafe

impl<T> Send for RingBuffer<T> where
    T: Send

impl<T> Sync for RingBuffer<T> where
    T: Sync

impl<T> Unpin for RingBuffer<T> where
    T: Unpin

impl<T> UnwindSafe for RingBuffer<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.