Skip to content

Commit beeafed

Browse files
author
Markus Westerlind
committed
Fix review comments
1 parent 7d7d5e9 commit beeafed

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/undo_log.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,33 @@ where
6262
}
6363
}
6464

65-
/// A trait which allows snapshots to be done at specific points. Each snapshot can then be used to
65+
/// A trait which extends `UndoLogs` to allow snapshots to be done at specific points. Each snapshot can then be used to
6666
/// rollback any changes to an underlying data structures if they were not desirable.
6767
///
6868
/// Each snapshot must be consumed linearly with either `rollback_to` or `commit`.
6969
pub trait Snapshots<T>: UndoLogs<T> {
7070
type Snapshot;
71+
72+
/// Returns true if `self` has made any changes since snapshot started.
7173
fn has_changes(&self, snapshot: &Self::Snapshot) -> bool {
7274
!self.actions_since_snapshot(snapshot).is_empty()
7375
}
76+
77+
/// Returns the slice of actions that were taken since the snapshot began.
7478
fn actions_since_snapshot(&self, snapshot: &Self::Snapshot) -> &[T];
7579

80+
/// Starts a new snapshot. That snapshot must eventually either be committed via a call to
81+
/// commit or rollback via rollback_to. Snapshots can be nested (i.e., you can start a snapshot
82+
/// whilst another snapshot is in progress) but you must then commit or rollback the inner
83+
/// snapshot before attempting to commit or rollback the outer snapshot.
7684
fn start_snapshot(&mut self) -> Self::Snapshot;
77-
fn rollback_to<R>(&mut self, values: impl FnOnce() -> R, snapshot: Self::Snapshot)
85+
86+
/// Rollback (undo) the changes made to `storage` since the snapshot.
87+
fn rollback_to<R>(&mut self, storage: impl FnOnce() -> R, snapshot: Self::Snapshot)
7888
where
7989
R: Rollback<T>;
8090

91+
/// Commit: keep the changes that have been made since the snapshot began
8192
fn commit(&mut self, snapshot: Self::Snapshot);
8293
}
8394

@@ -96,11 +107,11 @@ where
96107
fn start_snapshot(&mut self) -> Self::Snapshot {
97108
U::start_snapshot(self)
98109
}
99-
fn rollback_to<R>(&mut self, values: impl FnOnce() -> R, snapshot: Self::Snapshot)
110+
fn rollback_to<R>(&mut self, storage: impl FnOnce() -> R, snapshot: Self::Snapshot)
100111
where
101112
R: Rollback<T>,
102113
{
103-
U::rollback_to(self, values, snapshot)
114+
U::rollback_to(self, storage, snapshot)
104115
}
105116

106117
fn commit(&mut self, snapshot: Self::Snapshot) {
@@ -213,7 +224,7 @@ impl<T> std::ops::Index<usize> for VecLog<T> {
213224
}
214225
}
215226

216-
/// A trait implemented for types which can be rolled back using actions of type `U`.
227+
/// A trait implemented for storage types (like `SnapshotVecStorage`) which can be rolled back using actions of type `U`.
217228
pub trait Rollback<U> {
218229
fn reverse(&mut self, undo: U);
219230
}

0 commit comments

Comments
 (0)