[PATCH] Add custom debug impl for large types
Export this patch
---
bitmap/src/dense.rs | 12 +++++++++++-
bitmap/src/sparse.rs | 14 +++++++++++++-
isabella/src/db/mod.rs | 11 +++++++++++
isabella/src/game/mod.rs | 2 +-
isabella/src/index/unique_fixed.rs | 11 +++++++++++
isabella/src/strings.rs | 10 ++++++++++
6 files changed, 57 insertions(+), 3 deletions(-)
diff --git a/bitmap/src/dense.rs b/bitmap/src/dense.rs
index cd4dec2..1aaeb51 100644
--- a/bitmap/src/dense.rs
@@ -1,3 +1,4 @@
+use std::fmt::Debug;
use std::ops::{BitAnd, BitOr, Not};
use super::util::div_with_rem;
@@ -5,12 +6,21 @@ use super::{BitmapError, ItemID};
/// DenseBitmap stores one bit for each record that's indexed. It has a fixed
/// size assigned at creation and cannot be resized.
-#[derive(Debug, PartialEq, Eq)]
+#[derive(PartialEq, Eq)]
pub struct DenseBitmap {
chunks: Vec<usize>,
size: usize,
}
+impl Debug for DenseBitmap {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("DenseBitmap")
+ .field("chunks.len()", &self.chunks.len())
+ .field("size", &self.size)
+ .finish()
+ }
+}
+
pub struct DenseBitmapIterator<'a> {
bitmap: &'a DenseBitmap,
item_id: usize,
diff --git a/bitmap/src/sparse.rs b/bitmap/src/sparse.rs
index 68dbaa1..8100103 100644
--- a/bitmap/src/sparse.rs
@@ -1,3 +1,5 @@
+use std::fmt::Debug;
+
use serde::{Deserialize, Serialize};
use super::{BitmapError, ItemID};
@@ -10,13 +12,23 @@ pub struct Run {
/// SparseBitmap stores contiguous runs of the same value, rather than each bit
/// individually. It has a fixed size assigned at creation and cannot be
/// resized.
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Clone, Serialize, Deserialize)]
pub struct SparseBitmap {
runs: Vec<Run>,
size: usize,
run_length: usize,
}
+impl Debug for SparseBitmap {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("SparseBitmap")
+ .field("runs.len()", &self.runs.len())
+ .field("size", &self.size)
+ .field("run_length", &self.run_length)
+ .finish()
+ }
+}
+
impl SparseBitmap {
pub fn of_size(size: usize) -> Self {
// initially, we only have one run, so everything is 0s.
diff --git a/isabella/src/db/mod.rs b/isabella/src/db/mod.rs
index e7864ec..66393cc 100644
--- a/isabella/src/db/mod.rs
+++ b/isabella/src/db/mod.rs
@@ -1,3 +1,5 @@
+use std::fmt::Debug;
+
use pgn::PgnFile;
use serde::{Deserialize, Serialize};
use shakmaty::Chess;
@@ -13,6 +15,15 @@ pub struct GameDB {
strings: StringsTable,
}
+impl Debug for GameDB {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("GameDB")
+ .field("games.len()", &self.games.len())
+ .field("strings", &self.strings)
+ .finish()
+ }
+}
+
impl GameDB {
pub fn new() -> Self {
GameDB {
diff --git a/isabella/src/game/mod.rs b/isabella/src/game/mod.rs
index 51104a6..4b79357 100644
--- a/isabella/src/game/mod.rs
+++ b/isabella/src/game/mod.rs
@@ -14,7 +14,7 @@ pub enum StartingPosition {
Custom(#[serde(with = "chess_serde")] Chess),
}
-#[derive(Default, Serialize, Deserialize)]
+#[derive(Default, Debug, Serialize, Deserialize)]
pub struct Game {
pub starting_position: StartingPosition,
#[serde(default, with = "vec_move_def")]
diff --git a/isabella/src/index/unique_fixed.rs b/isabella/src/index/unique_fixed.rs
index 2b3815a..b7bf23b 100644
--- a/isabella/src/index/unique_fixed.rs
+++ b/isabella/src/index/unique_fixed.rs
@@ -1,3 +1,5 @@
+use std::fmt::Debug;
+
use serde::{Deserialize, Serialize};
/// UniqueFixedIndex is a fixed-size container allowing locating a given value
@@ -15,6 +17,15 @@ pub struct UniqueFixedIndex<K, V> {
vals: Vec<V>,
}
+impl<K, V> Debug for UniqueFixedIndex<K, V> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("UniqueFixedIndex")
+ .field("keys.len()", &self.keys.len())
+ .field("vals.len()", &self.vals.len())
+ .finish()
+ }
+}
+
impl<K, V> UniqueFixedIndex<K, V>
where
K: Ord,
diff --git a/isabella/src/strings.rs b/isabella/src/strings.rs
index 80e5142..0cc1af5 100644
--- a/isabella/src/strings.rs
+++ b/isabella/src/strings.rs
@@ -1,5 +1,6 @@
use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;
+use std::fmt::Debug;
use std::hash::{Hash, Hasher};
use serde::{Deserialize, Serialize};
@@ -16,6 +17,15 @@ pub struct StringsTable {
ids: HashMap<StringHash, StringID>,
}
+impl Debug for StringsTable {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("StringsTable")
+ .field("strings.len()", &self.strings.len())
+ .field("ids.len()", &self.ids.len())
+ .finish()
+ }
+}
+
impl StringsTable {
/// create a new StringsTable with no default capacity
pub fn new() -> Self {
--
2.34.1
Applied, thank you!