1
Fork 0

Improve Debug implementations of OccupiedError.

This commit is contained in:
Mara Bos 2021-03-04 15:56:38 +01:00
parent f6fe24aab3
commit 69d95e232a
2 changed files with 14 additions and 3 deletions

View file

@ -86,8 +86,9 @@ pub struct OccupiedError<'a, K: 'a, V: 'a> {
impl<K: Debug + Ord, V: Debug> Debug for OccupiedError<'_, K, V> { impl<K: Debug + Ord, V: Debug> Debug for OccupiedError<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OccupiedError") f.debug_struct("OccupiedError")
.field("entry", &self.entry) .field("key", self.entry.key())
.field("value", &self.value) .field("old_value", self.entry.get())
.field("new_value", &self.value)
.finish() .finish()
} }
} }

View file

@ -1889,7 +1889,6 @@ impl<K: Debug, V> Debug for VacantEntry<'_, K, V> {
/// ///
/// Contains the occupied entry, and the value that was not inserted. /// Contains the occupied entry, and the value that was not inserted.
#[unstable(feature = "map_try_insert", issue = "none")] #[unstable(feature = "map_try_insert", issue = "none")]
#[derive(Debug)]
pub struct OccupiedError<'a, K: 'a, V: 'a> { pub struct OccupiedError<'a, K: 'a, V: 'a> {
/// The entry in the map that was already occupied. /// The entry in the map that was already occupied.
pub entry: OccupiedEntry<'a, K, V>, pub entry: OccupiedEntry<'a, K, V>,
@ -1897,6 +1896,17 @@ pub struct OccupiedError<'a, K: 'a, V: 'a> {
pub value: V, pub value: V,
} }
#[unstable(feature = "map_try_insert", issue = "none")]
impl<K: Debug, V: Debug> Debug for OccupiedError<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OccupiedError")
.field("key", self.entry.key())
.field("old_value", self.entry.get())
.field("new_value", &self.value)
.finish()
}
}
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S> { impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S> {
type Item = (&'a K, &'a V); type Item = (&'a K, &'a V);