about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-07-19 12:50:15 -0700
committerGitHub <noreply@github.com>2016-07-19 12:50:15 -0700
commit48c245411b4a550bfe68e1a3eb703e8a22926402 (patch)
tree61cf45c81985b311eb458ca44bca069e70d5cd43
parent27e766d7bc84be992c8ddef710affc92ef4a0adf (diff)
parentdae311ea3b6e37e5ad2b7b3d42cfe953c2221855 (diff)
downloadrust-48c245411b4a550bfe68e1a3eb703e8a22926402.tar.gz
rust-48c245411b4a550bfe68e1a3eb703e8a22926402.zip
Auto merge of #34885 - GuillaumeGomez:btree_map_debug, r=alexcrichton
Add debug for btree_map::{Entry, VacantEntry, OccupiedEntry}
-rw-r--r--src/libcollections/btree/map.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs
index aea7a1c13a2..ef94aae78f4 100644
--- a/src/libcollections/btree/map.rs
+++ b/src/libcollections/btree/map.rs
@@ -326,6 +326,20 @@ pub enum Entry<'a, K: 'a, V: 'a> {
              OccupiedEntry<'a, K, V>),
 }
 
+#[stable(feature= "debug_btree_map", since = "1.12.0")]
+impl<'a, K: 'a + Debug + Ord, V: 'a + Debug> Debug for Entry<'a, K, V> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
+            Vacant(ref v) => f.debug_tuple("Entry")
+                              .field(v)
+                              .finish(),
+            Occupied(ref o) => f.debug_tuple("Entry")
+                                .field(o)
+                                .finish(),
+        }
+    }
+}
+
 /// A vacant Entry.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct VacantEntry<'a, K: 'a, V: 'a> {
@@ -337,6 +351,15 @@ pub struct VacantEntry<'a, K: 'a, V: 'a> {
     _marker: PhantomData<&'a mut (K, V)>,
 }
 
+#[stable(feature= "debug_btree_map", since = "1.12.0")]
+impl<'a, K: 'a + Debug + Ord, V: 'a> Debug for VacantEntry<'a, K, V> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.debug_tuple("VacantEntry")
+         .field(self.key())
+         .finish()
+    }
+}
+
 /// An occupied Entry.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
@@ -348,6 +371,16 @@ pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
     _marker: PhantomData<&'a mut (K, V)>,
 }
 
+#[stable(feature= "debug_btree_map", since = "1.12.0")]
+impl<'a, K: 'a + Debug + Ord, V: 'a + Debug> Debug for OccupiedEntry<'a, K, V> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.debug_struct("OccupiedEntry")
+         .field("key", self.key())
+         .field("value", self.get())
+         .finish()
+    }
+}
+
 // An iterator for merging two sorted sequences into one
 struct MergeIter<K, V, I: Iterator<Item = (K, V)>> {
     left: Peekable<I>,