Skip to content

Commit ce442b4

Browse files
Add debug for hash_map::{Entry, VacantEntry, OccupiedEntry}
1 parent a63e3fa commit ce442b4

File tree

1 file changed

+33
-0
lines changed
  • src/libstd/collections/hash

1 file changed

+33
-0
lines changed

src/libstd/collections/hash/map.rs

+33
Original file line numberDiff line numberDiff line change
@@ -1351,13 +1351,37 @@ pub enum Entry<'a, K: 'a, V: 'a> {
13511351
),
13521352
}
13531353

1354+
#[stable(feature= "debug_hash_map", since = "1.12.0")]
1355+
impl<'a, K: 'a + Debug, V: 'a + Debug> Debug for Entry<'a, K, V> {
1356+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1357+
match *self {
1358+
Vacant(ref v) => f.debug_tuple("Entry")
1359+
.field(v)
1360+
.finish(),
1361+
Occupied(ref o) => f.debug_tuple("Entry")
1362+
.field(o)
1363+
.finish(),
1364+
}
1365+
}
1366+
}
1367+
13541368
/// A view into a single occupied location in a HashMap.
13551369
#[stable(feature = "rust1", since = "1.0.0")]
13561370
pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
13571371
key: Option<K>,
13581372
elem: FullBucket<K, V, &'a mut RawTable<K, V>>,
13591373
}
13601374

1375+
#[stable(feature= "debug_hash_map", since = "1.12.0")]
1376+
impl<'a, K: 'a + Debug, V: 'a + Debug> Debug for OccupiedEntry<'a, K, V> {
1377+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1378+
f.debug_struct("OccupiedEntry")
1379+
.field("key", self.key())
1380+
.field("value", self.get())
1381+
.finish()
1382+
}
1383+
}
1384+
13611385
/// A view into a single empty location in a HashMap.
13621386
#[stable(feature = "rust1", since = "1.0.0")]
13631387
pub struct VacantEntry<'a, K: 'a, V: 'a> {
@@ -1366,6 +1390,15 @@ pub struct VacantEntry<'a, K: 'a, V: 'a> {
13661390
elem: VacantEntryState<K, V, &'a mut RawTable<K, V>>,
13671391
}
13681392

1393+
#[stable(feature= "debug_hash_map", since = "1.12.0")]
1394+
impl<'a, K: 'a + Debug, V: 'a> Debug for VacantEntry<'a, K, V> {
1395+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1396+
f.debug_tuple("VacantEntry")
1397+
.field(self.key())
1398+
.finish()
1399+
}
1400+
}
1401+
13691402
/// Possible states of a VacantEntry.
13701403
enum VacantEntryState<K, V, M> {
13711404
/// The index is occupied, but the key to insert has precedence,

0 commit comments

Comments
 (0)