@@ -62,22 +62,33 @@ where
62
62
}
63
63
}
64
64
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
66
66
/// rollback any changes to an underlying data structures if they were not desirable.
67
67
///
68
68
/// Each snapshot must be consumed linearly with either `rollback_to` or `commit`.
69
69
pub trait Snapshots < T > : UndoLogs < T > {
70
70
type Snapshot ;
71
+
72
+ /// Returns true if `self` has made any changes since snapshot started.
71
73
fn has_changes ( & self , snapshot : & Self :: Snapshot ) -> bool {
72
74
!self . actions_since_snapshot ( snapshot) . is_empty ( )
73
75
}
76
+
77
+ /// Returns the slice of actions that were taken since the snapshot began.
74
78
fn actions_since_snapshot ( & self , snapshot : & Self :: Snapshot ) -> & [ T ] ;
75
79
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.
76
84
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 )
78
88
where
79
89
R : Rollback < T > ;
80
90
91
+ /// Commit: keep the changes that have been made since the snapshot began
81
92
fn commit ( & mut self , snapshot : Self :: Snapshot ) ;
82
93
}
83
94
@@ -96,11 +107,11 @@ where
96
107
fn start_snapshot ( & mut self ) -> Self :: Snapshot {
97
108
U :: start_snapshot ( self )
98
109
}
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 )
100
111
where
101
112
R : Rollback < T > ,
102
113
{
103
- U :: rollback_to ( self , values , snapshot)
114
+ U :: rollback_to ( self , storage , snapshot)
104
115
}
105
116
106
117
fn commit ( & mut self , snapshot : Self :: Snapshot ) {
@@ -213,7 +224,7 @@ impl<T> std::ops::Index<usize> for VecLog<T> {
213
224
}
214
225
}
215
226
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`.
217
228
pub trait Rollback < U > {
218
229
fn reverse ( & mut self , undo : U ) ;
219
230
}
0 commit comments