[][src]Struct ringbuffer::GenericRingBuffer

pub struct GenericRingBuffer<T, Cap: ArrayLength<T>> { /* fields omitted */ }

The GenericRingBuffer struct is a RingBuffer implementation which does not require alloc. However it does depend on the typenum crate, to provide compile time integers without needing nightly rust. Unfortunately this is the only way to provide a compile time ringbuffer which does not require nightly rust like ConstGenericRingBuffer. Once const-generics are stable this struct will be depricated.

GenericRingBuffer allocates the ringbuffer on the stack, and the size must be known at compile time through typenum.

Example

use ringbuffer::{RingBuffer, GenericRingBuffer};
use ringbuffer::typenum; // for numbers as types in stable rust

let mut buffer = GenericRingBuffer::<_, typenum::U2>::new();

// 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: Default, Cap: ArrayLength<T>> GenericRingBuffer<T, Cap>[src]

It is only possible to create a Generic RingBuffer if the type T in it implements Default. This is because the array needs to be allocated at compile time, and needs to be filled with some default value to avoid unsafe.

pub fn new() -> Self[src]

Creates a new RingBuffer. The method is here for compatibility with the alloc version of RingBuffer. This method simply creates a default ringbuffer. The capacity is given as a type parameter.

Trait Implementations

impl<T: Debug, Cap: Debug + ArrayLength<T>> Debug for GenericRingBuffer<T, Cap>[src]

impl<T: Default, Cap: ArrayLength<T>> Default for GenericRingBuffer<T, Cap>[src]

fn default() -> Self[src]

Creates a buffer with a capacity specified through the Cap type parameter.

impl<T: Eq, Cap: Eq + ArrayLength<T>> Eq for GenericRingBuffer<T, Cap>[src]

impl<RB: 'static + Default, Cap: ArrayLength<RB>> FromIterator<RB> for GenericRingBuffer<RB, Cap>[src]

impl<T: 'static + Default, Cap: ArrayLength<T>> Index<isize> for GenericRingBuffer<T, Cap>[src]

type Output = T

The returned type after indexing.

impl<T: 'static + Default, Cap: ArrayLength<T>> IndexMut<isize> for GenericRingBuffer<T, Cap>[src]

impl<T: PartialEq, Cap: PartialEq + ArrayLength<T>> PartialEq<GenericRingBuffer<T, Cap>> for GenericRingBuffer<T, Cap>[src]

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

impl<T, Cap: ArrayLength<T>> StructuralEq for GenericRingBuffer<T, Cap>[src]

impl<T, Cap: ArrayLength<T>> StructuralPartialEq for GenericRingBuffer<T, Cap>[src]

Auto Trait Implementations

impl<T, Cap> Send for GenericRingBuffer<T, Cap> where
    T: Send

impl<T, Cap> Sync for GenericRingBuffer<T, Cap> where
    T: Sync

impl<T, Cap> Unpin for GenericRingBuffer<T, Cap> where
    <Cap as ArrayLength<T>>::ArrayType: 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.