Struct ripin::Stack
[−]
[src]
pub struct Stack<T>(_);
A growable stack implementing push/pop
actions.
use ripin::Stack; let mut stack = Stack::new(); stack.push(3); stack.push(4); stack.push(10); assert_eq!(stack.len(), 3); assert_eq!(stack.pop(), Some(10)); assert_eq!(stack.len(), 2);
Methods
impl<T> Stack<T>
[src]
fn new() -> Stack<T>
fn with_capacity(capacity: usize) -> Stack<T>
Creates an empty VecDeque with space for at least n elements.
Examples
use ripin::Stack; let mut stack: Stack<i32> = Stack::with_capacity(10);
fn len(&self) -> usize
Returns the number of elements in the set.
Examples
use ripin::Stack; let mut stack = Stack::new(); stack.push(3); assert_eq!(stack.len(), 1);
fn is_empty(&self) -> bool
Returns true if the set contains no elements.
Examples
use ripin::Stack; let mut stack = Stack::new(); assert_eq!(stack.is_empty(), true); stack.push(3); assert_eq!(stack.is_empty(), false);
fn push(&mut self, value: T)
Appends an element to the back of the stack.
Panics
Panics if the number of elements in the stack overflows a usize.
Examples
use ripin::Stack; let mut stack = Stack::new(); stack.push(3); assert_eq!(stack.pop(), Some(3)); assert_eq!(stack.pop(), None);
fn pop(&mut self) -> Option<T>
Removes the last element from the stack and returns it,
or None
if it is empty.
Examples
use ripin::Stack; let mut stack = Stack::new(); stack.push(3); stack.push(2); assert_eq!(stack.pop(), Some(2)); assert_eq!(stack.pop(), Some(3)); assert_eq!(stack.pop(), None);