rs_graph/collections/
stack.rs1pub trait ItemStack<I> {
19 fn is_empty(&self) -> bool {
20 self.len() == 0
21 }
22
23 fn len(&self) -> usize;
24
25 fn clear(&mut self);
26
27 fn push(&mut self, u: I);
28
29 fn pop(&mut self) -> Option<I>;
30
31 fn top(&self) -> Option<&I>;
32
33 fn top_mut(&mut self) -> Option<&mut I>;
34}
35
36impl<'a, I, D> ItemStack<I> for &'a mut D
37where
38 D: ItemStack<I>,
39{
40 fn is_empty(&self) -> bool {
41 (**self).is_empty()
42 }
43
44 fn len(&self) -> usize {
45 (**self).len()
46 }
47
48 fn clear(&mut self) {
49 (**self).clear()
50 }
51
52 fn push(&mut self, u: I) {
53 (**self).push(u)
54 }
55
56 fn pop(&mut self) -> Option<I> {
57 (**self).pop()
58 }
59
60 fn top(&self) -> Option<&I> {
61 (**self).top()
62 }
63
64 fn top_mut(&mut self) -> Option<&mut I> {
65 (**self).top_mut()
66 }
67}
68
69impl<I> ItemStack<I> for Vec<I> {
70 fn is_empty(&self) -> bool {
71 Vec::is_empty(self)
72 }
73
74 fn len(&self) -> usize {
75 Vec::len(self)
76 }
77
78 fn clear(&mut self) {
79 Vec::clear(self)
80 }
81
82 fn push(&mut self, u: I) {
83 Vec::push(self, u)
84 }
85
86 fn pop(&mut self) -> Option<I> {
87 Vec::pop(self)
88 }
89
90 fn top(&self) -> Option<&I> {
91 self.as_slice().last()
92 }
93
94 fn top_mut(&mut self) -> Option<&mut I> {
95 self.as_mut_slice().last_mut()
96 }
97}