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

A stack is a collection that follows the LIFO (last-in-first-out) principle. This means that elements are added to the top of the stack and removed from the top of the stack. This implementation uses a linked-based structure.

Examples

use trait_based_collection::{prelude::*, Stack};

let mut queue: Stack<u32> = Stack::new_default();
queue.add(1);
queue.add(2);
queue.add(3);

assert_eq!(queue.peek(), Some(&3));
assert_eq!(queue.remove(), Some(3));
assert_eq!(queue.remove(), Some(2));
assert_eq!(queue.remove(), Some(1));
assert_eq!(queue.remove(), None);

Trait Implementations

Creates a new Collection with a default capacity. Read more
Adds an item to the Collection. Read more
Removes an item from the Collection. Read more
Returns an immutable reference of the item that will be removed next. Read more
Returns a mutable reference of the item that will be removed next. Read more
Returns a immutable reference to the n-th item in the Collection. Read more
Returns a mutable reference to the n-th item in the Collection. Read more
Returns the number of items in the Collection. Read more
Creates a new Collection with a specific capacity. Read more
Creates a new Collection with a capacity that is at least the specified capacity. Read more
Clears all items from the Collection while keeping the capacity. Read more
Checks if the Collection is empty. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Creates a value from an iterator. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. 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
The type of reference the immutable iterator (Iter) iterates over the items in the Collection. The reference is only valid for the duration of the iteration. Read more
The type of mutable reference the mutable iterator (IterMut) iterates over the items in the Collection. The reference is only valid for the duration of the iteration. Read more
Which kind of iterator is returned by iter. Read more
Which kind of iterator is returned by iter_mut. Read more
Creates an immutable iterator over the items in the Collection without consuming them. Read more
Creates a mutable iterator over the items in the Collection without consuming them. 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.

Converts the given value to a String. Read more
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.