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>
impl<T, const INITCAP: usize> CircularQueue<T, INITCAP>
Sourcepub const fn len(&self) -> usize
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.
Sourcepub fn new() -> Self
pub fn new() -> Self
creates an empty queue with default initial capacity defined by const generic INITCAP
Sourcepub fn push_back(&mut self, x: T)
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.
Sourcepub fn push_front(&mut self, x: T)
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.
Sourcepub fn pop_back(&mut self) -> Option<T>
pub fn pop_back(&mut self) -> Option<T>
returns (moves) value at back of the queue, if it exists.
Sourcepub fn pop_front(&mut self) -> Option<T>
pub fn pop_front(&mut self) -> Option<T>
returns (moves) value at front of the queue, if it exists.
Trait Implementations§
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().
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().