Skip to content

Commit e812ba6

Browse files
committed
Manual Debug impls so we don't require S: Debug
1 parent 1c30bd1 commit e812ba6

File tree

3 files changed

+93
-6
lines changed

3 files changed

+93
-6
lines changed

evmap/src/lib.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ impl<V: ?Sized> fmt::Debug for Predicate<V> {
255255

256256
/// A pending map operation.
257257
#[non_exhaustive]
258-
#[derive(PartialEq, Eq, Debug)]
259258
pub(crate) enum Operation<K, V, M> {
260259
/// Replace the set of entries for this key with this value.
261260
Replace(K, V),
@@ -297,6 +296,34 @@ pub(crate) enum Operation<K, V, M> {
297296
JustCloneRHandle,
298297
}
299298

299+
impl<K, V, M> fmt::Debug for Operation<K, V, M>
300+
where
301+
K: fmt::Debug,
302+
V: fmt::Debug,
303+
M: fmt::Debug,
304+
{
305+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
306+
match *self {
307+
Operation::Replace(ref a, ref b) => f.debug_tuple("Replace").field(a).field(b).finish(),
308+
Operation::Add(ref a, ref b) => f.debug_tuple("Add").field(a).field(b).finish(),
309+
Operation::RemoveValue(ref a, ref b) => {
310+
f.debug_tuple("RemoveValue").field(a).field(b).finish()
311+
}
312+
Operation::RemoveEntry(ref a) => f.debug_tuple("RemoveEntry").field(a).finish(),
313+
#[cfg(feature = "eviction")]
314+
Operation::EmptyAt(ref a) => f.debug_tuple("EmptyAt").field(a).finish(),
315+
Operation::Clear(ref a) => f.debug_tuple("Clear").field(a).finish(),
316+
Operation::Purge => f.debug_tuple("Purge").finish(),
317+
Operation::Retain(ref a, ref b) => f.debug_tuple("Retain").field(a).field(b).finish(),
318+
Operation::Fit(ref a) => f.debug_tuple("Fit").field(a).finish(),
319+
Operation::Reserve(ref a, ref b) => f.debug_tuple("Reserve").field(a).field(b).finish(),
320+
Operation::MarkReady => f.debug_tuple("MarkReady").finish(),
321+
Operation::SetMeta(ref a) => f.debug_tuple("SetMeta").field(a).finish(),
322+
Operation::JustCloneRHandle => f.debug_tuple("JustCloneRHandle").finish(),
323+
}
324+
}
325+
}
326+
300327
/// Options for how to initialize the map.
301328
///
302329
/// In particular, the options dictate the hashing function, meta type, and initial capacity of the

evmap/src/read/read_ref.rs

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{inner::Inner, values::Values};
22
use left_right::ReadGuard;
33
use std::borrow::Borrow;
44
use std::collections::hash_map::RandomState;
5+
use std::fmt;
56
use std::hash::{BuildHasher, Hash};
67

78
// To make [`WriteHandle`] and friends work.
@@ -15,7 +16,6 @@ use crate::WriteHandle;
1516
///
1617
/// Since the map remains immutable while this lives, the methods on this type all give you
1718
/// unguarded references to types contained in the map.
18-
#[derive(Debug)]
1919
pub struct MapReadRef<'rh, K, V, M = (), S = RandomState>
2020
where
2121
K: Hash + Eq,
@@ -25,6 +25,22 @@ where
2525
pub(super) guard: ReadGuard<'rh, Inner<K, V, M, S>>,
2626
}
2727

28+
impl<'rh, K, V, M, S> fmt::Debug for MapReadRef<'rh, K, V, M, S>
29+
where
30+
K: Hash + Eq,
31+
V: Eq + Hash,
32+
S: BuildHasher,
33+
K: fmt::Debug,
34+
M: fmt::Debug,
35+
V: fmt::Debug,
36+
{
37+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38+
f.debug_struct("MapReadRef")
39+
.field("guard", &self.guard)
40+
.finish()
41+
}
42+
}
43+
2844
impl<'rh, K, V, M, S> MapReadRef<'rh, K, V, M, S>
2945
where
3046
K: Hash + Eq,
@@ -169,7 +185,6 @@ where
169185
}
170186

171187
/// An [`Iterator`] over keys and values in the evmap.
172-
#[derive(Debug)]
173188
pub struct ReadGuardIter<'rg, K, V, S>
174189
where
175190
K: Eq + Hash,
@@ -179,6 +194,18 @@ where
179194
iter: <&'rg crate::inner::MapImpl<K, Values<V, S>, S> as IntoIterator>::IntoIter,
180195
}
181196

197+
impl<'rg, K, V, S> fmt::Debug for ReadGuardIter<'rg, K, V, S>
198+
where
199+
K: Eq + Hash + fmt::Debug,
200+
V: Eq + Hash,
201+
S: BuildHasher,
202+
V: fmt::Debug,
203+
{
204+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
205+
f.debug_tuple("ReadGuardIter").field(&self.iter).finish()
206+
}
207+
}
208+
182209
impl<'rg, K, V, S> Iterator for ReadGuardIter<'rg, K, V, S>
183210
where
184211
K: Eq + Hash,
@@ -192,7 +219,6 @@ where
192219
}
193220

194221
/// An [`Iterator`] over keys.
195-
#[derive(Debug)]
196222
pub struct KeysIter<'rg, K, V, S>
197223
where
198224
K: Eq + Hash,
@@ -202,6 +228,18 @@ where
202228
iter: <&'rg crate::inner::MapImpl<K, Values<V, S>, S> as IntoIterator>::IntoIter,
203229
}
204230

231+
impl<'rg, K, V, S> fmt::Debug for KeysIter<'rg, K, V, S>
232+
where
233+
K: Eq + Hash + fmt::Debug,
234+
V: Eq + Hash,
235+
S: BuildHasher,
236+
V: fmt::Debug,
237+
{
238+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
239+
f.debug_tuple("KeysIter").field(&self.iter).finish()
240+
}
241+
}
242+
205243
impl<'rg, K, V, S> Iterator for KeysIter<'rg, K, V, S>
206244
where
207245
K: Eq + Hash,
@@ -215,7 +253,6 @@ where
215253
}
216254

217255
/// An [`Iterator`] over value sets.
218-
#[derive(Debug)]
219256
pub struct ValuesIter<'rg, K, V, S>
220257
where
221258
K: Eq + Hash,
@@ -225,6 +262,18 @@ where
225262
iter: <&'rg crate::inner::MapImpl<K, Values<V, S>, S> as IntoIterator>::IntoIter,
226263
}
227264

265+
impl<'rg, K, V, S> fmt::Debug for ValuesIter<'rg, K, V, S>
266+
where
267+
K: Eq + Hash + fmt::Debug,
268+
V: Eq + Hash,
269+
S: BuildHasher,
270+
V: fmt::Debug,
271+
{
272+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
273+
f.debug_tuple("ValuesIter").field(&self.iter).finish()
274+
}
275+
}
276+
228277
impl<'rg, K, V, S> Iterator for ValuesIter<'rg, K, V, S>
229278
where
230279
K: Eq + Hash,

evmap/src/values.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,25 @@ impl<'a, T, S> IntoIterator for &'a Values<T, S> {
108108
}
109109
}
110110

111-
#[derive(Debug)]
112111
pub enum ValuesIter<'a, T, S> {
113112
#[doc(hidden)]
114113
Short(<&'a smallvec::SmallVec<[T; 1]> as IntoIterator>::IntoIter),
115114
#[doc(hidden)]
116115
Long(<&'a hashbag::HashBag<T, S> as IntoIterator>::IntoIter),
117116
}
118117

118+
impl<'a, T, S> fmt::Debug for ValuesIter<'a, T, S>
119+
where
120+
T: fmt::Debug,
121+
{
122+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123+
match *self {
124+
ValuesIter::Short(ref it) => f.debug_tuple("Short").field(it).finish(),
125+
ValuesIter::Long(ref it) => f.debug_tuple("Long").field(it).finish(),
126+
}
127+
}
128+
}
129+
119130
impl<'a, T, S> Iterator for ValuesIter<'a, T, S> {
120131
type Item = &'a T;
121132
fn next(&mut self) -> Option<Self::Item> {

0 commit comments

Comments
 (0)