Skip to content

Commit bc52bdc

Browse files
committed
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: #35447
1 parent f0bab98 commit bc52bdc

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/libcollections/vec.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,15 @@ pub struct IntoIter<T> {
17131713
end: *const T,
17141714
}
17151715

1716+
#[stable(feature = "vec_intoiter_debug", since = "")]
1717+
impl<T: fmt::Debug> fmt::Debug for IntoIter<T> {
1718+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1719+
f.debug_tuple("IntoIter")
1720+
.field(&self.as_slice())
1721+
.finish()
1722+
}
1723+
}
1724+
17161725
impl<T> IntoIter<T> {
17171726
/// Returns the remaining items of this iterator as a slice.
17181727
///

src/libcollectionstest/vec.rs

+8
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,14 @@ fn test_into_iter_as_mut_slice() {
501501
assert_eq!(into_iter.as_slice(), &['y', 'c']);
502502
}
503503

504+
#[test]
505+
fn test_into_iter_debug() {
506+
let vec = vec!['a', 'b', 'c'];
507+
let into_iter = vec.into_iter();
508+
let debug = format!("{:?}", into_iter);
509+
assert_eq!(debug, "IntoIter(['a', 'b', 'c'])");
510+
}
511+
504512
#[test]
505513
fn test_into_iter_count() {
506514
assert_eq!(vec![1, 2, 3].into_iter().count(), 3);

0 commit comments

Comments
 (0)