cop/
rewind.rs

1/// Restore the state of mutable data structures.
2///
3/// In the presence of backtracking, mutable data structures
4/// (such as the substitution) often need to be reset to an earlier state.
5/// Such data structures should implement `Rewind<T>` if
6/// `T` is a cheap and small characterisation of their state.
7pub trait Rewind<T> {
8    /// Rewind to some state.
9    fn rewind(&mut self, state: T);
10}
11
12impl<T> Rewind<usize> for alloc::vec::Vec<T> {
13    fn rewind(&mut self, state: usize) {
14        assert!(self.len() >= state);
15        self.truncate(state)
16    }
17}