[][src]Struct circular_queue::CircularQueue

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

A circular buffer-like queue.

Methods

impl<T> CircularQueue<T>[src]

pub fn with_capacity(capacity: usize) -> Self[src]

Constructs a new, empty CircularQueue<T> with the requested capacity.

Examples

use circular_queue::CircularQueue;

let mut queue: CircularQueue<i32> = CircularQueue::with_capacity(5);

pub fn len(&self) -> usize[src]

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

pub fn is_empty(&self) -> bool[src]

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

pub fn capacity(&self) -> usize[src]

Returns the capacity of the queue.

Examples

use circular_queue::CircularQueue;

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

pub fn clear(&mut self)[src]

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

pub fn push(&mut self, x: T)[src]

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

pub fn iter(&self) -> Iter<T>[src]

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

pub fn iter_mut(&mut self) -> IterMut<T>[src]

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

pub fn asc_iter(&self) -> AscIter<T>[src]

Returns an ascending iterator over the queue's contents.

The iterator goes from the least recently pushed items to the newest 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.asc_iter();

assert_eq!(iter.next(), Some(&2));
assert_eq!(iter.next(), Some(&3));
assert_eq!(iter.next(), Some(&4));

pub fn asc_iter_mut(&mut self) -> AscIterMut<T>[src]

Returns a mutable ascending iterator over the queue's contents.

The iterator goes from the least recently pushed items to the newest 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.asc_iter_mut();

assert_eq!(iter.next(), Some(&mut 2));
assert_eq!(iter.next(), Some(&mut 3));
assert_eq!(iter.next(), Some(&mut 4));

Trait Implementations

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

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

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

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

Auto Trait Implementations

impl<T> Send for CircularQueue<T> where
    T: Send

impl<T> Sync for CircularQueue<T> where
    T: Sync

impl<T> Unpin for CircularQueue<T> where
    T: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.