about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2016-08-15 23:45:12 -0400
committerCorey Farwell <coreyf@rwell.org>2016-08-15 23:45:12 -0400
commitbc52bdcedcb34e303d2a3a450b541dfbf002281e (patch)
tree6a581116d0662f699d7a963f885e7fc582d6baa0 /src
parentf0bab98695f0a4877daabad9a5b0ba3e66121392 (diff)
downloadrust-bc52bdcedcb34e303d2a3a450b541dfbf002281e.tar.gz
rust-bc52bdcedcb34e303d2a3a450b541dfbf002281e.zip
Implement `Debug` for `std::vec::IntoIter`.
Display all the remaining items of the iterator, similar to the `Debug`
implementation for `core::slice::Iter`:

https://github.com/rust-lang/rust/blob/f0bab98695f0a4877daabad9a5b0ba3e66121392/src/libcore/slice.rs#L930-L937

Using the `as_slice` method that was added in:

https://github.com/rust-lang/rust/pull/35447
Diffstat (limited to 'src')
-rw-r--r--src/libcollections/vec.rs9
-rw-r--r--src/libcollectionstest/vec.rs8
2 files changed, 17 insertions, 0 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs
index a6f817a8962..7008411d0f8 100644
--- a/src/libcollections/vec.rs
+++ b/src/libcollections/vec.rs
@@ -1713,6 +1713,15 @@ pub struct IntoIter<T> {
     end: *const T,
 }
 
+#[stable(feature = "vec_intoiter_debug", since = "")]
+impl<T: fmt::Debug> fmt::Debug for IntoIter<T> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.debug_tuple("IntoIter")
+            .field(&self.as_slice())
+            .finish()
+    }
+}
+
 impl<T> IntoIter<T> {
     /// Returns the remaining items of this iterator as a slice.
     ///
diff --git a/src/libcollectionstest/vec.rs b/src/libcollectionstest/vec.rs
index 9556174bd22..86f4bbd3c4d 100644
--- a/src/libcollectionstest/vec.rs
+++ b/src/libcollectionstest/vec.rs
@@ -502,6 +502,14 @@ fn test_into_iter_as_mut_slice() {
 }
 
 #[test]
+fn test_into_iter_debug() {
+    let vec = vec!['a', 'b', 'c'];
+    let into_iter = vec.into_iter();
+    let debug = format!("{:?}", into_iter);
+    assert_eq!(debug, "IntoIter(['a', 'b', 'c'])");
+}
+
+#[test]
 fn test_into_iter_count() {
     assert_eq!(vec![1, 2, 3].into_iter().count(), 3);
 }