RingBuffer

Struct RingBuffer 

Source
pub struct RingBuffer<T, const SIZE: usize> { /* private fields */ }
Expand description

A RingBuffer holds SIZE elements of type T.

Implementations§

Source§

impl<T: Default + Copy, const SIZE: usize> RingBuffer<T, SIZE>

Source

pub fn new() -> Self

Make a new RingBuffer!

Source

pub fn push_overwrite(&mut self, elem: T) -> Option<T>

Push something onto the buffer. If the buffer is full, the oldest element is returned.

Source

pub fn push_unless_full(&mut self, elem: T) -> Result<(), Error>

Push something onto the buffer, unless the buffer is full.

Source

pub fn pop(&mut self) -> Option<T>

Pop the buffer. If it is empty, then None is returned.

Source

pub fn len(&self) -> usize

How many elements are in the buffer?

Source

pub fn is_empty(&self) -> bool

Is the buffer empty?

Source

pub fn is_full(&self) -> bool

Is the buffer full?

Source§

impl<T: Default + Copy, const SIZE: usize> RingBuffer<T, SIZE>

Source

pub fn iter(&self) -> IntoIteratorRingbuffer<'_, T, SIZE>

Make an immutable non-consuming iterator

Trait Implementations§

Source§

impl<T: Default + Copy, const SIZE: usize> Default for RingBuffer<T, SIZE>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T: Default + Copy, const SIZE: usize> IntoIterator for &'a RingBuffer<T, SIZE>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIteratorRingbuffer<'a, T, SIZE>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: Default + Copy, const SIZE: usize> IntoIterator for RingBuffer<T, SIZE>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = ConsumingIntoIteratorRingbuffer<T, SIZE>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, const SIZE: usize> Freeze for RingBuffer<T, SIZE>
where T: Freeze,

§

impl<T, const SIZE: usize> RefUnwindSafe for RingBuffer<T, SIZE>
where T: RefUnwindSafe,

§

impl<T, const SIZE: usize> Send for RingBuffer<T, SIZE>
where T: Send,

§

impl<T, const SIZE: usize> Sync for RingBuffer<T, SIZE>
where T: Sync,

§

impl<T, const SIZE: usize> Unpin for RingBuffer<T, SIZE>
where T: Unpin,

§

impl<T, const SIZE: usize> UnwindSafe for RingBuffer<T, SIZE>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.