Struct kernel::collections::ring_buffer::RingBuffer
source · pub struct RingBuffer<'a, T: 'a> { /* private fields */ }
Implementations§
source§impl<'a, T: Copy> RingBuffer<'a, T>
impl<'a, T: Copy> RingBuffer<'a, T>
pub fn new(ring: &'a mut [T]) -> RingBuffer<'a, T>
sourcepub fn available_len(&self) -> usize
pub fn available_len(&self) -> usize
Returns the number of elements that can be enqueued until the ring buffer is full.
sourcepub fn as_slices(&'a self) -> (Option<&'a [T]>, Option<&'a [T]>)
pub fn as_slices(&'a self) -> (Option<&'a [T]>, Option<&'a [T]>)
Returns up to 2 slices that together form the contents of the ring buffer.
Returns:
(None, None)
if the buffer is empty.(Some(slice), None)
if the head is before the tail (therefore all the contents is contiguous).(Some(left), Some(right))
if the head is after the tail. In that case, the logical contents of the buffer is[left, right].concat()
(although physically the “left” slice is stored after the “right” slice).
Trait Implementations§
source§impl<T: Copy> Queue<T> for RingBuffer<'_, T>
impl<T: Copy> Queue<T> for RingBuffer<'_, T>
source§fn remove_first_matching<F>(&mut self, f: F) -> Option<T>
fn remove_first_matching<F>(&mut self, f: F) -> Option<T>
Removes the first element for which the provided closure returns true
.
This walks the ring buffer and, upon finding a matching element, removes it. It then shifts all subsequent elements forward (filling the hole created by removing the element).
If an element was removed, this function returns it as Some(elem)
.
source§fn has_elements(&self) -> bool
fn has_elements(&self) -> bool
Returns true if there are any items in the queue, false otherwise.
source§fn enqueue(&mut self, val: T) -> bool
fn enqueue(&mut self, val: T) -> bool
If the queue isn’t full, add a new element to the back of the queue.
Returns whether the element was added.
Auto Trait Implementations§
impl<'a, T> Freeze for RingBuffer<'a, T>
impl<'a, T> RefUnwindSafe for RingBuffer<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for RingBuffer<'a, T>where
T: Send,
impl<'a, T> Sync for RingBuffer<'a, T>where
T: Sync,
impl<'a, T> Unpin for RingBuffer<'a, T>
impl<'a, T> !UnwindSafe for RingBuffer<'a, T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more