Skip to content

Commit 4ddce3a

Browse files
committed
impl Debug for IterMut and ValuesMut
1 parent b41fc6b commit 4ddce3a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

RELEASES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- `IndexMap::get_index_mut` now returns `Option<(&K, &mut V)>`, changing
1414
the key part from `&mut K` to `&K`. There is also a new alternative
1515
`MutableKeys::get_index_mut2` to access the former behavior.
16+
17+
- `IterMut` and `ValuesMut` now implement `Debug`.
1618

1719

1820
- 1.8.1

src/map.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,12 @@ impl<K, V> ExactSizeIterator for ValuesMut<'_, K, V> {
984984

985985
impl<K, V> FusedIterator for ValuesMut<'_, K, V> {}
986986

987-
// TODO: `impl Debug for ValuesMut` once we have MSRV 1.53 for `slice::IterMut::as_slice`
987+
impl<K, V: fmt::Debug> fmt::Debug for ValuesMut<'_, K, V> {
988+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
989+
let iter = self.iter.as_slice().iter().map(Bucket::value_ref);
990+
f.debug_list().entries(iter).finish()
991+
}
992+
}
988993

989994
/// An owning iterator over the values of a `IndexMap`.
990995
///
@@ -1095,7 +1100,12 @@ impl<K, V> ExactSizeIterator for IterMut<'_, K, V> {
10951100

10961101
impl<K, V> FusedIterator for IterMut<'_, K, V> {}
10971102

1098-
// TODO: `impl Debug for IterMut` once we have MSRV 1.53 for `slice::IterMut::as_slice`
1103+
impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IterMut<'_, K, V> {
1104+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1105+
let iter = self.iter.as_slice().iter().map(Bucket::refs);
1106+
f.debug_list().entries(iter).finish()
1107+
}
1108+
}
10991109

11001110
/// An owning iterator over the entries of a `IndexMap`.
11011111
///

0 commit comments

Comments
 (0)