Skip to content

Commit 2e390b4

Browse files
authored
Merge pull request #5 from WaDelma/master
Added Debug implementations to UnificationTable.
2 parents 403e708 + 0afe9fd commit 2e390b4

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/snapshot_vec.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
2222
use self::UndoLog::*;
2323

24+
use std::fmt;
2425
use std::mem;
2526
use std::ops;
2627

28+
#[derive(Debug)]
2729
pub enum UndoLog<D: SnapshotVecDelegate> {
2830
/// Indicates where a snapshot started.
2931
OpenSnapshot,
@@ -46,6 +48,20 @@ pub struct SnapshotVec<D: SnapshotVecDelegate> {
4648
undo_log: Vec<UndoLog<D>>,
4749
}
4850

51+
impl<D> fmt::Debug for SnapshotVec<D>
52+
where D: SnapshotVecDelegate,
53+
D: fmt::Debug,
54+
D::Undo: fmt::Debug,
55+
D::Value: fmt::Debug
56+
{
57+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
58+
fmt.debug_struct("SnapshotVec")
59+
.field("values", &self.values)
60+
.field("undo_log", &self.undo_log)
61+
.finish()
62+
}
63+
}
64+
4965
// Snapshots are tokens that should be created/consumed linearly.
5066
pub struct Snapshot {
5167
// Length of the undo log at the time the snapshot was taken.

src/unify/backing_vec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub trait UnificationStore: ops::Index<usize, Output = VarValue<Key<Self>>> + Cl
3939

4040
/// Backing store for an in-place unification table.
4141
/// Not typically used directly.
42-
#[derive(Clone)]
42+
#[derive(Clone, Debug)]
4343
pub struct InPlace<K: UnifyKey> {
4444
values: sv::SnapshotVec<Delegate<K>>
4545
}
@@ -96,7 +96,7 @@ impl<K> ops::Index<usize> for InPlace<K>
9696
}
9797
}
9898

99-
#[derive(Copy, Clone)]
99+
#[derive(Copy, Clone, Debug)]
100100
struct Delegate<K>(PhantomData<K>);
101101

102102
impl<K: UnifyKey> sv::SnapshotVecDelegate for Delegate<K> {
@@ -107,7 +107,7 @@ impl<K: UnifyKey> sv::SnapshotVecDelegate for Delegate<K> {
107107
}
108108

109109
#[cfg(feature = "persistent")]
110-
#[derive(Clone)]
110+
#[derive(Clone, Debug)]
111111
pub struct Persistent<K: UnifyKey> {
112112
values: DVec<VarValue<K>>
113113
}

src/unify/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub struct VarValue<K: UnifyKey> { // FIXME pub
176176
/// cloning the table is an O(1) operation.
177177
/// - This implies that ordinary operations are quite a bit slower though.
178178
/// - Requires the `persistent` feature be selected in your Cargo.toml file.
179-
#[derive(Clone)]
179+
#[derive(Clone, Debug)]
180180
pub struct UnificationTable<S: UnificationStore> {
181181
/// Indicates the current value of each key.
182182
values: S,

0 commit comments

Comments
 (0)