Skip to main content

CircularQueue

Struct CircularQueue 

Source
pub struct CircularQueue<T, const INITCAP: usize = 64> { /* private fields */ }
Expand description

A circular queue using a vector of options underneath. Can’t use an array because the size of the array is part of its type in Rust. The unused portions of the vector will hold value None. Look at the source code for details. This program was based on a roughly equivalent C++ Version.

Implementations§

Source§

impl<T, const INITCAP: usize> CircularQueue<T, INITCAP>

Source

pub const fn len(&self) -> usize

number of values in queue. This function can be called from a const context, which means it can be evaluated by the compiler, although this is unlikely since vectors are heap-allocated.

Source

pub fn capacity(&self) -> usize

current capacity of queue

Source

pub fn new() -> Self

creates an empty queue with default initial capacity defined by const generic INITCAP

Source

pub fn push_back(&mut self, x: T)

inserts a value at the back of the queue, wrapping around to the right if necessary. Increases capacity if necessary.

Source

pub fn push_front(&mut self, x: T)

inserts a value at the front of the queue, wrapping around to the left if necessary. Increases capacity if necessary.

Source

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

returns (moves) value at back of the queue, if it exists.

Source

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

returns (moves) value at front of the queue, if it exists.

Source

pub fn mapfun<F: FnMut(&mut T)>(&mut self, f: F)

Maps mutable closure f over each value of the queue. The closure has the ability to mutate each value as well as mutate its environment (see the source for the test_main function).

Source

pub fn iter<'lt>(&'lt self) -> Cqiter<'lt, T, INITCAP>

returns an immutable iterator, allows for x in queue.iter()

Trait Implementations§

Source§

impl<T, const C: usize> Index<usize> for CircularQueue<T, C>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const C: usize> IndexMut<usize> for CircularQueue<T, C>

Source§

fn index_mut(&mut self, i: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'lt, T, const C: usize> IntoIterator for &'lt CircularQueue<T, C>

Implementing this trait means we can say for x in &queue, which is equivalent to for x in queue.iter().

Source§

type Item = &'lt T

The type of the elements being iterated over.
Source§

type IntoIter = Cqiter<'lt, T, C>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, const INITCAP: usize> Freeze for CircularQueue<T, INITCAP>

§

impl<T, const INITCAP: usize> RefUnwindSafe for CircularQueue<T, INITCAP>
where T: RefUnwindSafe,

§

impl<T, const INITCAP: usize> Send for CircularQueue<T, INITCAP>
where T: Send,

§

impl<T, const INITCAP: usize> Sync for CircularQueue<T, INITCAP>
where T: Sync,

§

impl<T, const INITCAP: usize> Unpin for CircularQueue<T, INITCAP>
where T: Unpin,

§

impl<T, const INITCAP: usize> UnsafeUnpin for CircularQueue<T, INITCAP>

§

impl<T, const INITCAP: usize> UnwindSafe for CircularQueue<T, INITCAP>
where T: UnwindSafe,

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.