| 15 | /// in order to rewind the stack to a previous state. |
| 16 | #[derive(Debug)] |
| 17 | pub struct Stack<T: Clone> { |
| 18 | /// All elements in the stack. |
| 19 | cache: Vec<T>, |
| 20 | /// All elements that are in previous snapshots but may not be in the next state. |
| 21 | /// They will be pushed back to `cache` if the snapshot is restored, |
| 22 | /// otherwise be dropped if the snapshot is cleared. |
| 23 | /// |
| 24 | /// Those elements from a sequence of snapshots are stacked in one [`Vec`], and |
| 25 | /// `popped.len() == lengths.iter().map(|(len, remained)| len - remained).sum()` |
| 26 | popped: Vec<T>, |
| 27 | /// Every element corresponds to a snapshot, and each element has two fields: |
| 28 | /// - Length of `cache` when corresponding snapshot is taken (AKA `len`). |
| 29 | /// - Count of elements that come from corresponding snapshot |
| 30 | /// and are still in next snapshot or current state (AKA `remained`). |
| 31 | /// |
| 32 | /// And `len` is never less than `remained`. |
| 33 | /// |
| 34 | /// On restoring, the `cache` can be divided into two parts: |
| 35 | /// - `0..remained` are untouched since the snapshot is taken. |
| 36 | /// |
| 37 | /// There's nothing to do with those elements. Just let them stay where they are. |
| 38 | /// |
| 39 | /// - `remained..cache.len()` are pushed after the snapshot is taken. |
| 40 | lengths: Vec<(usize, usize)>, |
| 41 | } |
| 42 | |
| 43 | impl<T: Clone> Default for Stack<T> { |
| 44 | fn default() -> Self { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…