From d85d82ab2234cf08e2e86575d0cdebefdb819831 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 4 Mar 2021 15:57:26 +0100 Subject: Implement Error for OccupiedError. --- library/alloc/src/collections/btree/map/entry.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'library/alloc/src') diff --git a/library/alloc/src/collections/btree/map/entry.rs b/library/alloc/src/collections/btree/map/entry.rs index cc508f30a61..a5ece31d67b 100644 --- a/library/alloc/src/collections/btree/map/entry.rs +++ b/library/alloc/src/collections/btree/map/entry.rs @@ -93,6 +93,19 @@ impl Debug for OccupiedError<'_, K, V> { } } +#[unstable(feature = "map_try_insert", issue = "none")] +impl<'a, K: Debug + Ord, V: Debug> fmt::Display for OccupiedError<'a, K, V> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "failed to insert {:?}, key {:?} already exists with value {:?}", + self.value, + self.entry.key(), + self.entry.get(), + ) + } +} + impl<'a, K: Ord, V> Entry<'a, K, V> { /// Ensures a value is in the entry by inserting the default if empty, and returns /// a mutable reference to the value in the entry. -- cgit 1.4.1-3-g733a5