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>
impl<T, const N: usize> RingBufRef<T, N>
pub const INIT_0: RingBufRef<T, N>
pub const fn new() -> Self
pub fn is_empty(&self) -> bool
pub fn len(&self) -> u32
pub fn is_full(&self) -> bool
pub fn capacity(&self) -> usize
Sourcepub fn writer_front(&self) -> Option<&mut T>
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
Sourcepub fn commit(&self) -> Result<(), ErrCode>
pub fn commit(&self) -> Result<(), ErrCode>
Commit whatever at the write index location by moving the write index
Sourcepub fn push(&self, val: T) -> Result<(), ErrCode>
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)
Sourcepub fn reader_front(&self) -> Option<&T>
pub fn reader_front(&self) -> Option<&T>
Returns an Option of reference to location at read index
Sourcepub fn reader_front_mut(&self) -> Option<&mut T>
pub fn reader_front_mut(&self) -> Option<&mut T>
Returns an Option of mutable reference to location at read index