Lines Matching full:stack
14 /// Implementation of a `Stack` which maintains an log of `StackOp`s in order to rewind the stack
17 pub struct Stack<T: Clone> { struct
23 impl<T: Clone> Stack<T> { argument
24 /// Creates a new `Stack`.
26 Stack { in new()
33 /// Returns `true` if the stack is currently empty.
39 /// Returns the top-most `&T` in the `Stack`.
44 /// Pushes a `T` onto the `Stack`.
50 /// Pops the top-most `T` from the `Stack`.
59 /// Returns the size of the stack
64 /// Takes a snapshot of the current `Stack`.
74 /// Rewinds the `Stack` to the most recent `snapshot()`. If no `snapshot()` has been taken, this
75 /// function return the stack to its initial state.
89 // Rewind the stack to a particular index
105 impl<T: Clone> Index<Range<usize>> for Stack<T> { implementation
121 use super::Stack;
125 let mut stack = Stack::new(); in snapshot_with_empty() localVariable
127 stack.snapshot(); in snapshot_with_empty()
129 assert!(stack.is_empty()); in snapshot_with_empty()
131 stack.push(0); in snapshot_with_empty()
132 stack.restore(); in snapshot_with_empty()
133 assert!(stack.is_empty()); in snapshot_with_empty()
138 let mut stack = Stack::new(); in snapshot_twice() localVariable
140 stack.push(0); in snapshot_twice()
142 stack.snapshot(); in snapshot_twice()
143 stack.snapshot(); in snapshot_twice()
144 stack.restore(); in snapshot_twice()
145 stack.restore(); in snapshot_twice()
147 assert_eq!(stack[0..stack.len()], [0]); in snapshot_twice()
152 let mut stack = Stack::new(); in stack_ops() localVariable
155 assert!(stack.is_empty()); in stack_ops()
156 assert_eq!(stack.peek(), None); in stack_ops()
157 assert_eq!(stack.pop(), None); in stack_ops()
160 stack.push(0); in stack_ops()
161 assert!(!stack.is_empty()); in stack_ops()
162 assert_eq!(stack.peek(), Some(&0)); in stack_ops()
165 stack.push(1); in stack_ops()
166 assert!(!stack.is_empty()); in stack_ops()
167 assert_eq!(stack.peek(), Some(&1)); in stack_ops()
170 assert_eq!(stack.pop(), Some(1)); in stack_ops()
171 assert!(!stack.is_empty()); in stack_ops()
172 assert_eq!(stack.peek(), Some(&0)); in stack_ops()
175 stack.push(2); in stack_ops()
176 assert!(!stack.is_empty()); in stack_ops()
177 assert_eq!(stack.peek(), Some(&2)); in stack_ops()
180 stack.push(3); in stack_ops()
181 assert!(!stack.is_empty()); in stack_ops()
182 assert_eq!(stack.peek(), Some(&3)); in stack_ops()
184 // Take a snapshot of the current stack in stack_ops()
186 stack.snapshot(); in stack_ops()
189 assert_eq!(stack.pop(), Some(3)); in stack_ops()
190 assert!(!stack.is_empty()); in stack_ops()
191 assert_eq!(stack.peek(), Some(&2)); in stack_ops()
193 // Take a snapshot of the current stack in stack_ops()
195 stack.snapshot(); in stack_ops()
198 assert_eq!(stack.pop(), Some(2)); in stack_ops()
199 assert!(!stack.is_empty()); in stack_ops()
200 assert_eq!(stack.peek(), Some(&0)); in stack_ops()
203 assert_eq!(stack.pop(), Some(0)); in stack_ops()
204 assert!(stack.is_empty()); in stack_ops()
208 stack.restore(); in stack_ops()
209 assert_eq!(stack.pop(), Some(2)); in stack_ops()
210 assert_eq!(stack.pop(), Some(0)); in stack_ops()
211 assert_eq!(stack.pop(), None); in stack_ops()
215 stack.restore(); in stack_ops()
216 assert_eq!(stack.pop(), Some(3)); in stack_ops()
217 assert_eq!(stack.pop(), Some(2)); in stack_ops()
218 assert_eq!(stack.pop(), Some(0)); in stack_ops()
219 assert_eq!(stack.pop(), None); in stack_ops()