RingBufRef

Struct RingBufRef 

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

A ring buffer of capacity N holding items of type T. Non power-of-two N is supported but less efficient.

Implementations§

Source§

impl<T, const N: usize> RingBufRef<T, N>

Source

pub const INIT_0: RingBufRef<T, N>

Source

pub const fn new() -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> u32

Source

pub fn is_full(&self) -> bool

Source

pub fn capacity(&self) -> usize

Source

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

Returns the write index location as mutable reference. The Result<> return enforces handling of return type I.e. if user does not check for push success, the compiler generates warnings Calling stage twice without commit in between results in the same location written! We could add some protection by remembering this during alloc but this will incur runtime cost

Source

pub fn commit(&self) -> Result<(), ErrCode>

Commit whatever at the write index location by moving the write index

Source

pub fn push(&self, val: T) -> Result<(), ErrCode>

Alloc and commit in one step by providing the value T to be written val’s ownership is moved. (Question: it seems if T implements Clone, compiler copies T)

Source

pub fn reader_front(&self) -> Option<&T>

Returns an Option of reference to location at read index

Source

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

Returns an Option of mutable reference to location at read index

Source

pub fn pop(&self) -> Result<(), ErrCode>

Consume the item at rd_idx

Trait Implementations§

Source§

impl<T, const N: usize> Sync for RingBufRef<T, N>

Auto Trait Implementations§

§

impl<T, const N: usize> !Freeze for RingBufRef<T, N>

§

impl<T, const N: usize> !RefUnwindSafe for RingBufRef<T, N>

§

impl<T, const N: usize> Send for RingBufRef<T, N>
where T: Send,

§

impl<T, const N: usize> Unpin for RingBufRef<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for RingBufRef<T, N>
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.