Skip to content

Commit

Permalink
Rollup merge of #34937 - GuillaumeGomez:hash_map_entry_debug, r=apase…
Browse files Browse the repository at this point in the history
…l422

Add debug for hash_map::{Entry, VacantEntry, OccupiedEntry}

r? @alexcrichton
  • Loading branch information
GuillaumeGomez authored Jul 21, 2016
2 parents 1006f79 + ce442b4 commit 22a14a8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,13 +1351,37 @@ pub enum Entry<'a, K: 'a, V: 'a> {
),
}

#[stable(feature= "debug_hash_map", since = "1.12.0")]
impl<'a, K: 'a + Debug, V: 'a + Debug> Debug for Entry<'a, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Vacant(ref v) => f.debug_tuple("Entry")
.field(v)
.finish(),
Occupied(ref o) => f.debug_tuple("Entry")
.field(o)
.finish(),
}
}
}

/// A view into a single occupied location in a HashMap.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
key: Option<K>,
elem: FullBucket<K, V, &'a mut RawTable<K, V>>,
}

#[stable(feature= "debug_hash_map", since = "1.12.0")]
impl<'a, K: 'a + Debug, V: 'a + Debug> Debug for OccupiedEntry<'a, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("OccupiedEntry")
.field("key", self.key())
.field("value", self.get())
.finish()
}
}

/// A view into a single empty location in a HashMap.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct VacantEntry<'a, K: 'a, V: 'a> {
Expand All @@ -1366,6 +1390,15 @@ pub struct VacantEntry<'a, K: 'a, V: 'a> {
elem: VacantEntryState<K, V, &'a mut RawTable<K, V>>,
}

#[stable(feature= "debug_hash_map", since = "1.12.0")]
impl<'a, K: 'a + Debug, V: 'a> Debug for VacantEntry<'a, K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("VacantEntry")
.field(self.key())
.finish()
}
}

/// Possible states of a VacantEntry.
enum VacantEntryState<K, V, M> {
/// The index is occupied, but the key to insert has precedence,
Expand Down

0 comments on commit 22a14a8

Please sign in to comment.