pub struct Queue<T> { /* private fields */ }
Expand description

Queue Struct

Implementations

Creates a new Queue

Example

Creating a new Queue of i32

use linked_lists_rs::queue::Queue;
let queue: Queue<i32> = Queue::new();

Push a new value on the end of the Queue

Example
let mut queue = Queue::new();

queue.push(5);

assert_eq!(Some(5), queue.pop());

Pops and return the value on the front of the Queue Returns None if the Queue is empty

Example
let mut queue = Queue::new();

queue.push(5);

assert_eq!(Some(5), queue.pop());
assert_eq!(None, queue.pop());

Return a reference to the value on the front of the Queue Returns None if the Queue is empty

Example
let mut queue = Queue::new();

queue.push(5);

assert_eq!(Some(&5), queue.peek());
assert_eq!(Some(5), queue.pop());
assert_eq!(None, queue.peek());

Return a mutable reference to the value on the front of the Queue Returns None if the Queue is empty

Example
let mut queue = Queue::new();

queue.push(5);

assert_eq!(Some(&mut 5), queue.peek_mut());
queue.peek_mut().map(|mut v| *v *= 5);
assert_eq!(Some(25), queue.pop());
assert_eq!(None, queue.peek_mut());

Iterator to the Queue Consumes the data structure on iteration

Example
let mut queue = Queue::new();

// Insert values into the queue
for x in [1, 2, 3] {
    queue.push(x);
}

// Iterate the queue and verify its values
for (i, x) in std::iter::zip(queue, [1, 2, 3]) {
    assert_eq!(i, x);
}

Reference Iterator to the Queue

Example
let mut queue = Queue::new();

// Insert values into the stack
for x in [1, 2, 3] {
    queue.push(x);
}

// Use iter to iterate the stack and verify its values
for (i, x) in std::iter::zip(&queue, [1, 2, 3]) {
    assert_eq!(i, &x);
}

// Stack is not consumed
assert_eq!(Some(&1), queue.peek());

Mutable Reference Iterator to the Queue

Example
let mut queue = Queue::new();

// Insert values into the stack
for x in [1, 2, 3] {
    queue.push(x);
}

// Use iter_mut to iterate the stack and mutate it's values
for i in &mut queue {
    *i *= 2;
}

// Assert values mutate as expected
for x in [2, 4, 6] {
    assert_eq!(Some(x), queue.pop());
}

Trait Implementations

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.