1#[derive(Clone)]
3pub struct Stack<T> {
4 stack: Vec<T>,
5}
6
7impl<T> Stack<T> {
8 pub fn new(capacity: usize) -> Stack<T> {
10 Stack {
11 stack: Vec::with_capacity(capacity),
12 }
13 }
14
15 #[inline]
17 pub fn push(&mut self, value: T) {
18 self.stack.push(value);
19 }
20
21 #[inline]
23 pub fn pop(&mut self) -> Option<T> {
24 self.stack.pop()
25 }
26
27 #[inline]
29 pub fn len(&self) -> usize {
30 self.stack.len()
31 }
32
33 #[inline]
35 pub fn is_empty(&self) -> bool {
36 self.stack.is_empty()
37 }
38
39 #[inline]
41 pub fn peek(&self) -> &T {
42 self.stack.last().unwrap()
43 }
44
45 #[inline]
47 pub fn contains(&self, value: &T) -> bool
48 where
49 T: PartialEq,
50 {
51 self.stack.contains(value)
52 }
53}
54
55impl Stack<(u16, bool)> {
56 pub fn iter(&self) -> std::slice::Iter<(u16, bool)> {
57 self.stack.iter()
58 }
59}
60
61impl IntoIterator for Stack<(u16, bool)> {
62 type Item = (u16, bool);
63 type IntoIter = std::vec::IntoIter<(u16, bool)>;
64
65 fn into_iter(self) -> Self::IntoIter {
66 self.stack.into_iter()
67 }
68}