Struct kernel::collections::ring_buffer::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>,

§

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

§

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.