diff options
| author | Steven Fackler <sfackler@gmail.com> | 2015-03-26 22:42:29 -0700 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2015-03-28 10:33:51 -0700 |
| commit | 4037f2a368edd75c561bc6f3d8c6f0d644bc4180 (patch) | |
| tree | 25ef8c2faee1ff9f30bf1d82d557bc50d4d90f00 /src/libcollections | |
| parent | 3e7385aae9d58c8e12137d7c07aad48551048c13 (diff) | |
| download | rust-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/libcollections')
| -rw-r--r-- | src/libcollections/btree/map.rs | 11 | ||||
| -rw-r--r-- | src/libcollections/btree/set.rs | 11 | ||||
| -rw-r--r-- | src/libcollections/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcollections/linked_list.rs | 11 |
4 files changed, 13 insertions, 21 deletions
diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index d2b45f4b049..93978e31de5 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -904,14 +904,11 @@ impl<K: Ord, V: Ord> Ord for BTreeMap<K, V> { #[stable(feature = "rust1", since = "1.0.0")] impl<K: Debug, V: Debug> Debug for BTreeMap<K, V> { 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 { + builder = builder.entry(k, v); } - - write!(f, "}}") + builder.finish() } } diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 08ee5801482..db0cdd30b1b 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -628,14 +628,11 @@ impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>> for &'a BTreeSet<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<T: Debug> Debug for BTreeSet<T> { 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/libcollections/lib.rs b/src/libcollections/lib.rs index f774c1505b8..c769b3df37f 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -40,6 +40,7 @@ #![feature(str_char)] #![feature(convert)] #![feature(slice_patterns)] +#![feature(debug_builders)] #![cfg_attr(test, feature(rand, rustc_private, test, hash, collections))] #![cfg_attr(test, allow(deprecated))] // rand diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs index 908c78a17f4..56c880ca6e2 100644 --- a/src/libcollections/linked_list.rs +++ b/src/libcollections/linked_list.rs @@ -927,14 +927,11 @@ impl<A: Clone> Clone for LinkedList<A> { #[stable(feature = "rust1", since = "1.0.0")] impl<A: fmt::Debug> fmt::Debug for LinkedList<A> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "[")); - - for (i, e) in self.iter().enumerate() { - if i != 0 { try!(write!(f, ", ")); } - try!(write!(f, "{:?}", *e)); + let mut builder = f.debug_list(); + for e in self { + builder = builder.entry(e); } - - write!(f, "]") + builder.finish() } } |
