Skip to content

Commit 54c487e

Browse files
committed
Add raw entry Debug
1 parent e646424 commit 54c487e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/map/core/raw_entry_v1.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use super::raw::RawTableEntry;
1313
use super::{get_hash, IndexMapCore};
1414
use crate::{Equivalent, HashValue, IndexMap};
15+
use core::fmt;
1516
use core::hash::{BuildHasher, Hash, Hasher};
1617
use core::marker::PhantomData;
1718
use core::mem;
@@ -181,6 +182,12 @@ pub struct RawEntryBuilder<'a, K, V, S> {
181182
map: &'a IndexMap<K, V, S>,
182183
}
183184

185+
impl<K, V, S> fmt::Debug for RawEntryBuilder<'_, K, V, S> {
186+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
187+
f.debug_struct("RawEntryBuilder").finish_non_exhaustive()
188+
}
189+
}
190+
184191
impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S> {
185192
/// Access an entry by key.
186193
pub fn from_key<Q: ?Sized>(self, key: &Q) -> Option<(&'a K, &'a V)>
@@ -222,6 +229,12 @@ pub struct RawEntryBuilderMut<'a, K, V, S> {
222229
map: &'a mut IndexMap<K, V, S>,
223230
}
224231

232+
impl<K, V, S> fmt::Debug for RawEntryBuilderMut<'_, K, V, S> {
233+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
234+
f.debug_struct("RawEntryBuilderMut").finish_non_exhaustive()
235+
}
236+
}
237+
225238
impl<'a, K, V, S> RawEntryBuilderMut<'a, K, V, S> {
226239
/// Access an entry by key.
227240
pub fn from_key<Q: ?Sized>(self, key: &Q) -> RawEntryMut<'a, K, V, S>
@@ -269,6 +282,17 @@ pub enum RawEntryMut<'a, K, V, S> {
269282
Vacant(RawVacantEntryMut<'a, K, V, S>),
270283
}
271284

285+
impl<K: fmt::Debug, V: fmt::Debug, S> fmt::Debug for RawEntryMut<'_, K, V, S> {
286+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
287+
let mut tuple = f.debug_tuple("RawEntryMut");
288+
match self {
289+
Self::Vacant(v) => tuple.field(v),
290+
Self::Occupied(o) => tuple.field(o),
291+
};
292+
tuple.finish()
293+
}
294+
}
295+
272296
impl<'a, K, V, S> RawEntryMut<'a, K, V, S> {
273297
/// Inserts the given default key and value in the entry if it is vacant and returns mutable
274298
/// references to them. Otherwise mutable references to an already existent pair are returned.
@@ -320,6 +344,15 @@ pub struct RawOccupiedEntryMut<'a, K, V, S> {
320344
hash_builder: PhantomData<&'a S>,
321345
}
322346

347+
impl<K: fmt::Debug, V: fmt::Debug, S> fmt::Debug for RawOccupiedEntryMut<'_, K, V, S> {
348+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
349+
f.debug_struct("RawOccupiedEntryMut")
350+
.field("key", self.key())
351+
.field("value", self.get())
352+
.finish_non_exhaustive()
353+
}
354+
}
355+
323356
impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
324357
/// Return the index of the key-value pair
325358
#[inline]
@@ -478,6 +511,12 @@ pub struct RawVacantEntryMut<'a, K, V, S> {
478511
hash_builder: &'a S,
479512
}
480513

514+
impl<K, V, S> fmt::Debug for RawVacantEntryMut<'_, K, V, S> {
515+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
516+
f.debug_struct("RawVacantEntryMut").finish_non_exhaustive()
517+
}
518+
}
519+
481520
impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
482521
/// Return the index where a key-value pair may be inserted.
483522
pub fn index(&self) -> usize {

0 commit comments

Comments
 (0)