kernel::collections::ring_buffer

Struct RingBuffer

Source
pub struct RingBuffer<'a, T: 'a> { /* private fields */ }

Implementations§

Source§

impl<'a, T: Copy> RingBuffer<'a, T>

Source

pub fn new(ring: &'a mut [T]) -> RingBuffer<'a, T>

Source

pub fn available_len(&self) -> usize

Returns the number of elements that can be enqueued until the ring buffer is full.

Source

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>

Source§

fn remove_first_matching<F>(&mut self, f: F) -> Option<T>
where F: Fn(&T) -> bool,

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

Returns true if there are any items in the queue, false otherwise.
Source§

fn is_full(&self) -> bool

Returns true if the queue is full, false otherwise.
Source§

fn len(&self) -> usize

Returns how many elements are in the queue.
Source§

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.
Source§

fn push(&mut self, val: T) -> Option<T>

Add a new element to the back of the queue, poping one from the front if necessary.
Source§

fn dequeue(&mut self) -> Option<T>

Remove the element from the front of the queue.
Source§

fn empty(&mut self)

Remove all elements from the ring buffer.
Source§

fn retain<F>(&mut self, f: F)
where F: FnMut(&T) -> bool,

Retains only the elements that satisfy the predicate.

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> 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.