Struct circular_queue::CircularQueue
[−]
[src]
pub struct CircularQueue<T> { /* fields omitted */ }
A circular buffer-like queue.
Methods
impl<T> CircularQueue<T>
[src]
fn new(capacity: usize) -> Self
Constructs a new, empty CircularQueue<T>
.
Panics
Panics if the requested capacity is 0.
Examples
use circular_queue::CircularQueue; let mut queue: CircularQueue<i32> = CircularQueue::new(5);
fn len(&self) -> usize
Returns the current number of elements in the queue.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::new(5); queue.push(1); queue.push(2); queue.push(3); assert_eq!(queue.len(), 3);
fn capacity(&self) -> usize
Returns the capacity of the queue.
Examples
use circular_queue::CircularQueue; let queue: CircularQueue<i32> = CircularQueue::new(5); assert_eq!(queue.capacity(), 5);
fn clear(&mut self)
Clears the queue.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::new(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::new(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<'a>(&'a self) -> Iter<'a, 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::new(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));
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