Struct circular_queue::CircularQueue [] [src]

pub struct CircularQueue<T> { /* fields omitted */ }

A circular buffer-like queue.

Methods

impl<T> CircularQueue<T>
[src]

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);

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);

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());

Returns the capacity of the queue.

Examples

use circular_queue::CircularQueue;

let queue: CircularQueue<i32> = CircularQueue::with_capacity(5);
assert_eq!(queue.capacity(), 5);

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);

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));

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));

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]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Debug> Debug for CircularQueue<T>
[src]

Formats the value using the given formatter.