diff options
| author | Nazım Can Altınova <canaltinova@gmail.com> | 2020-08-10 17:49:39 +0200 |
|---|---|---|
| committer | Nazım Can Altınova <canaltinova@gmail.com> | 2020-08-10 23:06:05 +0200 |
| commit | c346e89db8a57e15111daa35685a2542d3be7c77 (patch) | |
| tree | 9ce153def9e9234c6c96b2d06f18a46eca6eec1b | |
| parent | 456738e3d1ad7dadffaed287d3055ca38b5fa375 (diff) | |
| download | rust-c346e89db8a57e15111daa35685a2542d3be7c77.tar.gz rust-c346e89db8a57e15111daa35685a2542d3be7c77.zip | |
Manually implement Debug for BTreeMap::ValuesMut struct
Deriving debug prints all the values including keys. But ValuesMut struct should only print the values.
| -rw-r--r-- | library/alloc/src/collections/btree/map.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 37bca05b976..a08c19e3df4 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -361,11 +361,17 @@ impl<K, V: fmt::Debug> fmt::Debug for Values<'_, K, V> { /// /// [`values_mut`]: BTreeMap::values_mut #[stable(feature = "map_values_mut", since = "1.10.0")] -#[derive(Debug)] pub struct ValuesMut<'a, K: 'a, V: 'a> { inner: IterMut<'a, K, V>, } +#[stable(feature = "map_values_mut", since = "1.10.0")] +impl<K, V: fmt::Debug> fmt::Debug for ValuesMut<'_, K, V> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_list().entries(self.inner.iter().map(|(_, val)| val)).finish() + } +} + /// An owning iterator over the keys of a `BTreeMap`. /// /// This `struct` is created by the [`into_keys`] method on [`BTreeMap`]. @@ -1519,6 +1525,14 @@ impl<K, V> ExactSizeIterator for IterMut<'_, K, V> { #[stable(feature = "fused", since = "1.26.0")] impl<K, V> FusedIterator for IterMut<'_, K, V> {} +impl<'a, K, V> IterMut<'a, K, V> { + /// Returns an iterator of references over the remaining items. + #[inline] + pub(super) fn iter(&self) -> Iter<'_, K, V> { + Iter { range: self.range.iter(), length: self.length } + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<K, V> IntoIterator for BTreeMap<K, V> { type Item = (K, V); @@ -2006,6 +2020,15 @@ impl<'a, K, V> RangeMut<'a, K, V> { unsafe fn next_unchecked(&mut self) -> (&'a mut K, &'a mut V) { unsafe { unwrap_unchecked(self.front.as_mut()).next_unchecked() } } + + /// Returns an iterator of references over the remaining items. + #[inline] + pub(super) fn iter(&self) -> Range<'_, K, V> { + Range { + front: self.front.as_ref().map(|f| f.reborrow()), + back: self.back.as_ref().map(|b| b.reborrow()), + } + } } #[stable(feature = "btree_range", since = "1.17.0")] |
