about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2015-03-26 22:42:29 -0700
committerSteven Fackler <sfackler@gmail.com>2015-03-28 10:33:51 -0700
commit4037f2a368edd75c561bc6f3d8c6f0d644bc4180 (patch)
tree25ef8c2faee1ff9f30bf1d82d557bc50d4d90f00 /src/libstd
parent3e7385aae9d58c8e12137d7c07aad48551048c13 (diff)
downloadrust-4037f2a368edd75c561bc6f3d8c6f0d644bc4180.tar.gz
rust-4037f2a368edd75c561bc6f3d8c6f0d644bc4180.zip
Update debug helpers and add list builder
The collections debug helpers no longer prefix output with the
collection name, in line with the current conventions for Debug
implementations. Implementations that want to preserve the current
behavior can simply add a `try!(write!(fmt, "TypeName "));` at the
beginning of the `fmt` method.

[breaking-change]
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/collections/hash/map.rs11
-rw-r--r--src/libstd/collections/hash/set.rs11
-rw-r--r--src/libstd/lib.rs1
3 files changed, 9 insertions, 14 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index f9e1cb877b6..fd62729cd8f 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -1226,14 +1226,11 @@ impl<K, V, S> Debug for HashMap<K, V, S>
     where K: Eq + Hash + Debug, V: Debug, S: HashState
 {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        try!(write!(f, "{{"));
-
-        for (i, (k, v)) in self.iter().enumerate() {
-            if i != 0 { try!(write!(f, ", ")); }
-            try!(write!(f, "{:?}: {:?}", *k, *v));
+        let mut builder = f.debug_map();
+        for (k, v) in self.iter() {
+            builder = builder.entry(k, v);
         }
-
-        write!(f, "}}")
+        builder.finish()
     }
 }
 
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs
index 0933b4f662a..44c3d8262a7 100644
--- a/src/libstd/collections/hash/set.rs
+++ b/src/libstd/collections/hash/set.rs
@@ -614,14 +614,11 @@ impl<T, S> fmt::Debug for HashSet<T, S>
           S: HashState
 {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        try!(write!(f, "{{"));
-
-        for (i, x) in self.iter().enumerate() {
-            if i != 0 { try!(write!(f, ", ")); }
-            try!(write!(f, "{:?}", *x));
+        let mut builder = f.debug_set();
+        for x in self {
+            builder = builder.entry(x);
         }
-
-        write!(f, "}}")
+        builder.finish()
     }
 }
 
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index 5f5f2fed567..b7cb8f9ed50 100644
--- a/src/libstd/lib.rs
+++ b/src/libstd/lib.rs
@@ -128,6 +128,7 @@
 #![feature(into_cow)]
 #![feature(slice_patterns)]
 #![feature(std_misc)]
+#![feature(debug_builders)]
 #![cfg_attr(test, feature(test, rustc_private, std_misc))]
 
 // Don't link to std. We are std.