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

A stack-like data structure implemented through a Vec.

The name “stack” for this type of structure comes from the analogy to a set of physical items stacked on top of each other, which makes it easy to take an item off the top of the stack, while getting to an item deeper in the stack may require taking off multiple other items first.

Considered as a linear data structure, or more abstractly a sequential collection, the push and pop operations occur only at one end of the structure, referred to as the top of the stack.

References:

Implementations

Initialize a stack of certain capacity.

Parameters
  • maxsize: Capacity of the collection. It limits how many items can be stored.

Removes the most recently added element that was not yet removed.

Returns

Returns the most recently added item. If nothing was added, None will be returned.

Complexity

Constant.

Adds an element to the collection.

Returns

Returns true if the collection has space left and item is successfully added, otherwise returns false.

Complexity

Constant.

Returns

Returns the size of collection, indicates how many items are added in the collection.

Note

Size and capacity are different concepts. Capacity limits how many items can be stored, while size indicates how many items is currently stored.

Peeks the last element added without tampering the collection.

Returns

Returns the most recently added item. If nothing was added, None will be returned.

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.