Skip to content

Commit

Permalink
Add raw entry Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Jan 24, 2024
1 parent e646424 commit 54c487e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/map/core/raw_entry_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use super::raw::RawTableEntry;
use super::{get_hash, IndexMapCore};
use crate::{Equivalent, HashValue, IndexMap};
use core::fmt;
use core::hash::{BuildHasher, Hash, Hasher};
use core::marker::PhantomData;
use core::mem;
Expand Down Expand Up @@ -181,6 +182,12 @@ pub struct RawEntryBuilder<'a, K, V, S> {
map: &'a IndexMap<K, V, S>,
}

impl<K, V, S> fmt::Debug for RawEntryBuilder<'_, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RawEntryBuilder").finish_non_exhaustive()
}
}

impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S> {
/// Access an entry by key.
pub fn from_key<Q: ?Sized>(self, key: &Q) -> Option<(&'a K, &'a V)>
Expand Down Expand Up @@ -222,6 +229,12 @@ pub struct RawEntryBuilderMut<'a, K, V, S> {
map: &'a mut IndexMap<K, V, S>,
}

impl<K, V, S> fmt::Debug for RawEntryBuilderMut<'_, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RawEntryBuilderMut").finish_non_exhaustive()
}
}

impl<'a, K, V, S> RawEntryBuilderMut<'a, K, V, S> {
/// Access an entry by key.
pub fn from_key<Q: ?Sized>(self, key: &Q) -> RawEntryMut<'a, K, V, S>
Expand Down Expand Up @@ -269,6 +282,17 @@ pub enum RawEntryMut<'a, K, V, S> {
Vacant(RawVacantEntryMut<'a, K, V, S>),
}

impl<K: fmt::Debug, V: fmt::Debug, S> fmt::Debug for RawEntryMut<'_, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut tuple = f.debug_tuple("RawEntryMut");
match self {
Self::Vacant(v) => tuple.field(v),
Self::Occupied(o) => tuple.field(o),
};
tuple.finish()
}
}

impl<'a, K, V, S> RawEntryMut<'a, K, V, S> {
/// Inserts the given default key and value in the entry if it is vacant and returns mutable
/// references to them. Otherwise mutable references to an already existent pair are returned.
Expand Down Expand Up @@ -320,6 +344,15 @@ pub struct RawOccupiedEntryMut<'a, K, V, S> {
hash_builder: PhantomData<&'a S>,
}

impl<K: fmt::Debug, V: fmt::Debug, S> fmt::Debug for RawOccupiedEntryMut<'_, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RawOccupiedEntryMut")
.field("key", self.key())
.field("value", self.get())
.finish_non_exhaustive()
}
}

impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
/// Return the index of the key-value pair
#[inline]
Expand Down Expand Up @@ -478,6 +511,12 @@ pub struct RawVacantEntryMut<'a, K, V, S> {
hash_builder: &'a S,
}

impl<K, V, S> fmt::Debug for RawVacantEntryMut<'_, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RawVacantEntryMut").finish_non_exhaustive()
}
}

impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
/// Return the index where a key-value pair may be inserted.
pub fn index(&self) -> usize {
Expand Down

0 comments on commit 54c487e

Please sign in to comment.