Skip to content

Commit ffbc9c3

Browse files
author
Markus Westerlind
committed
Add some documentation
1 parent 30daa1d commit ffbc9c3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/snapshot_vec.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,15 @@ impl<D: SnapshotVecDelegate, V: VecLike<D> + Default, L: Default> Default for Sn
156156
}
157157

158158
impl<D: SnapshotVecDelegate, V: VecLike<D> + Default, L: Default> SnapshotVec<D, V, L> {
159+
/// Creates a new `SnapshotVec`. If `L` is set to `()` then most mutating functions will not
160+
/// be accessible without calling `with_log` and supplying a compatibly `UndoLogs` instance.
159161
pub fn new() -> Self {
160162
Self::default()
161163
}
162164
}
163165

164166
impl<D: SnapshotVecDelegate, V: VecLike<D>, L> SnapshotVec<D, V, L> {
167+
/// Creates a `SnapshotVec` using the `undo_log`, allowing mutating methods to be called
165168
pub fn with_log<'a, L2>(&'a mut self, undo_log: L2) -> SnapshotVec<D, &'a mut V, L2>
166169
where
167170
L2: UndoLogs<UndoLog<D>>,

src/undo_log.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// A trait which allows actions (`T`) to be pushed which which allows the action to be undone at a
2+
/// later time if needed
13
pub trait UndoLogs<T> {
24
fn in_snapshot(&self) -> bool {
35
self.num_open_snapshots() > 0
@@ -41,6 +43,10 @@ where
4143
}
4244
}
4345

46+
/// A trait which allows snapshots to be done at specific points. Each snapshot can then be used to
47+
/// rollback any changes to an underlying data structures if they were not desirable.
48+
///
49+
/// Each snapshot must be consumed linearly with either `rollback_to` or `commit`.
4450
pub trait Snapshots<T>: UndoLogs<T> {
4551
type Snapshot;
4652
fn has_changes(&self, snapshot: &Self::Snapshot) -> bool {
@@ -92,6 +98,7 @@ impl<T> UndoLogs<T> for NoUndo {
9298
fn clear(&mut self) {}
9399
}
94100

101+
/// A basic undo log.
95102
#[derive(Clone, Debug)]
96103
pub struct VecLog<T> {
97104
log: Vec<T>,
@@ -187,6 +194,7 @@ impl<T> std::ops::Index<usize> for VecLog<T> {
187194
}
188195
}
189196

197+
/// A trait implemented for types which can be rolled back using actions of type `U`.
190198
pub trait Rollback<U> {
191199
fn reverse(&mut self, undo: U);
192200
}
@@ -200,7 +208,7 @@ where
200208
}
201209
}
202210

203-
// Snapshots are tokens that should be created/consumed linearly.
211+
/// Snapshots are tokens that should be created/consumed linearly.
204212
pub struct Snapshot {
205213
// Length of the undo log at the time the snapshot was taken.
206214
undo_len: usize,

0 commit comments

Comments
 (0)