Struct circular_queue::CircularQueue
[−]
[src]
pub struct CircularQueue<T> { /* fields omitted */ }
A circular buffer-like queue.
Methods
impl<T> CircularQueue<T>
[src]
fn with_capacity(capacity: usize) -> Self
Constructs a new, empty CircularQueue<T>
with the requested capacity.
Panics
Panics if the requested capacity is 0.
Examples
use circular_queue::CircularQueue; let mut queue: CircularQueue<i32> = CircularQueue::with_capacity(5);
fn len(&self) -> usize
Returns the current number of elements in the queue.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(5); queue.push(1); queue.push(2); queue.push(3); assert_eq!(queue.len(), 3);
fn is_empty(&self) -> bool
Returns true
if the queue contains no elements.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(5); assert!(queue.is_empty()); queue.push(1); assert!(!queue.is_empty());
fn capacity(&self) -> usize
Returns the capacity of the queue.
Examples
use circular_queue::CircularQueue; let queue: CircularQueue<i32> = CircularQueue::with_capacity(5); assert_eq!(queue.capacity(), 5);
fn clear(&mut self)
Clears the queue.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(5); queue.push(1); queue.push(2); queue.push(3); queue.clear(); assert_eq!(queue.len(), 0);
fn push(&mut self, x: T)
Pushes a new element into the queue.
Once the capacity is reached, pushing new items will overwrite old ones.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(3); queue.push(1); queue.push(2); queue.push(3); queue.push(4); assert_eq!(queue.len(), 3); let mut iter = queue.iter(); assert_eq!(iter.next(), Some(&4)); assert_eq!(iter.next(), Some(&3)); assert_eq!(iter.next(), Some(&2));
fn iter(&self) -> Iter<T>
Returns an iterator over the queue's contents.
The iterator goes from the most recently pushed items to the oldest ones.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(3); queue.push(1); queue.push(2); queue.push(3); queue.push(4); let mut iter = queue.iter(); assert_eq!(iter.next(), Some(&4)); assert_eq!(iter.next(), Some(&3)); assert_eq!(iter.next(), Some(&2));
fn iter_mut(&mut self) -> IterMut<T>
Returns a mutable iterator over the queue's contents.
The iterator goes from the most recently pushed items to the oldest ones.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(3); queue.push(1); queue.push(2); queue.push(3); queue.push(4); let mut iter = queue.iter_mut(); assert_eq!(iter.next(), Some(&mut 4)); assert_eq!(iter.next(), Some(&mut 3)); assert_eq!(iter.next(), Some(&mut 2));
Trait Implementations
impl<T: Clone> Clone for CircularQueue<T>
[src]
fn clone(&self) -> CircularQueue<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more