Skip to content

Commit f10d1d3

Browse files
author
Markus Westerlind
committed
Prevent 'Storage' types from being modified without a log
1 parent 9c416dc commit f10d1d3

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/snapshot_vec.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ where
9898
}
9999
}
100100

101+
#[allow(type_alias_bounds)]
102+
pub type SnapshotVecStorage<D: SnapshotVecDelegate> =
103+
SnapshotVec<D, Vec<<D as SnapshotVecDelegate>::Value>, ()>;
104+
101105
pub struct SnapshotVec<
102106
D: SnapshotVecDelegate,
103107
V: VecLike<D> = Vec<<D as SnapshotVecDelegate>::Value>,
@@ -153,9 +157,13 @@ impl<D: SnapshotVecDelegate, V: VecLike<D> + Default, L: Default> SnapshotVec<D,
153157
}
154158

155159
impl<D: SnapshotVecDelegate, V: VecLike<D>, L> SnapshotVec<D, V, L> {
156-
pub fn with_log(values: V, undo_log: L) -> Self {
160+
pub fn with_log<'a, L2>(&'a mut self, undo_log: L2) -> SnapshotVec<D, &'a mut V, L2>
161+
where
162+
L2: UndoLogs<UndoLog<D>>,
163+
&'a mut V: VecLike<D>,
164+
{
157165
SnapshotVec {
158-
values,
166+
values: &mut self.values,
159167
undo_log,
160168
_marker: PhantomData,
161169
}

src/unify/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ pub struct VarValue<K: UnifyKey> {
179179
/// - This implies that ordinary operations are quite a bit slower though.
180180
/// - Requires the `persistent` feature be selected in your Cargo.toml file.
181181
#[derive(Clone, Debug, Default)]
182-
pub struct UnificationTable<S: UnificationStoreBase> {
182+
pub struct UnificationTable<S> {
183183
/// Indicates the current value of each key.
184184
values: S,
185185
}
186186

187-
pub type UnificationStorage<K> = Vec<VarValue<K>>;
187+
pub type UnificationTableStorage<K> = UnificationTable<InPlace<K, Vec<VarValue<K>>, ()>>;
188188

189189
/// A unification table that uses an "in-place" vector.
190190
#[allow(type_alias_bounds)]
@@ -245,12 +245,18 @@ impl<K, V, L> UnificationTable<InPlace<K, V, L>>
245245
where
246246
K: UnifyKey,
247247
V: sv::VecLike<Delegate<K>>,
248-
L: UndoLogs<sv::UndoLog<Delegate<K>>>,
249248
{
250-
pub fn with_log(values: V, undo_log: L) -> Self {
251-
Self {
249+
pub fn with_log<'a, L2>(
250+
&'a mut self,
251+
undo_log: L2,
252+
) -> UnificationTable<InPlace<K, &'a mut V, L2>>
253+
where
254+
L2: UndoLogs<sv::UndoLog<Delegate<K>>>,
255+
&'a mut V: sv::VecLike<Delegate<K>>,
256+
{
257+
UnificationTable {
252258
values: InPlace {
253-
values: sv::SnapshotVec::with_log(values, undo_log),
259+
values: self.values.values.with_log(undo_log),
254260
},
255261
}
256262
}

0 commit comments

Comments
 (0)