Struct Queue

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

A ring-buffer based queue, with N elements stored inline. TODO: Make this growable.

Implementations§

Source§

impl<T: Clone + Copy, const N: usize> Queue<T, N>

Source

pub const fn new() -> Self

Create a new empty queue.

Source

pub fn push_back(&mut self, value: T) -> Result<(), KernelError>

Push a value onto the back of the queue.

value - The value to push onto the back of the queue.

Returns Ok(()) if the value was pushed onto the back of the queue, or an error if the queue is full.

Source

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

Pop a value from the front of the queue.

Returns the value at the front of the queue, or None if the queue is empty.

Source

pub fn insert(&mut self, index: usize, value: T) -> Result<(), KernelError>

Insert a value at the given index in the queue.

index - The index to insert the value at. value - The value to insert.

Returns Ok(()) if the value was inserted at the given index, or an error if the index is out of bounds.

Source

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

Returns the value at the front of the queue.

Source

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

Returns the value at the back of the queue.

Source

pub fn len(&self) -> usize

Returns the length of the queue.

Source

pub fn is_empty(&self) -> bool

Returns true if the queue is empty.

Source

pub fn grow_capacity(&mut self, new_size: usize) -> Result<(), KernelError>

Increases total space in the queue preserving queue-integrity, potentially reallocating and copying existing contents

new_size - The total amount of space in the queue afterwards

Returns Ok(()) if the queue was successfully enlargened or the requested size was smaller than the current capacity. Returns An error if the queue could not be grown

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for Queue<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for Queue<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> !Send for Queue<T, N>

§

impl<T, const N: usize> !Sync for Queue<T, N>

§

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

§

impl<T, const N: usize> UnwindSafe for Queue<T, N>

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.