[][src]Struct ringbuffer::AllocRingBuffer

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

The AllocRingBuffer is a RingBuffer which is based on a Vec. This means it allocates at runtime on the heap, and therefore needs the alloc crate. This struct and therefore the dependency on alloc can be disabled by disabling the alloc (default) feature.

Example

use ringbuffer::{AllocRingBuffer, RingBuffer};

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

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

// The last item we pushed is 5
assert_eq!(buffer.get(-1), Some(&5));

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

assert_eq!(buffer.peek(), Some(&5));
assert!(buffer.is_full());

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

Implementations

impl<T> AllocRingBuffer<T>[src]

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

Creates a RingBuffer with a certain capacity. This capacity is fixed.

pub fn new() -> Self[src]

Creates a RingBuffer with a capacity of RINGBUFFER_DEFAULT_CAPACITY.

Trait Implementations

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

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

fn default() -> Self[src]

Creates a buffer with a capacity of crate::RINGBUFFER_DEFAULT_CAPACITY.

impl<T: Eq> Eq for AllocRingBuffer<T>[src]

impl<RB: 'static + Default> FromIterator<RB> for AllocRingBuffer<RB>[src]

impl<T: 'static + Default> Index<isize> for AllocRingBuffer<T>[src]

type Output = T

The returned type after indexing.

impl<T: 'static + Default> IndexMut<isize> for AllocRingBuffer<T>[src]

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

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

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

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

Auto Trait Implementations

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

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

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

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> Same<T> for T

type Output = T

Should always be Self

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

type Error = Infallible

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.