From 4037f2a368edd75c561bc6f3d8c6f0d644bc4180 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 26 Mar 2015 22:42:29 -0700 Subject: 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] --- src/libstd/collections/hash/map.rs | 11 ++++------- src/libstd/collections/hash/set.rs | 11 ++++------- src/libstd/lib.rs | 1 + 3 files changed, 9 insertions(+), 14 deletions(-) (limited to 'src/libstd') 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 Debug for HashMap 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 fmt::Debug for HashSet 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. -- cgit 1.4.1-3-g733a5