Implement Debug
for std::vec::IntoIter
.
Display all the remaining items of the iterator, similar to the `Debug`
implementation for `core::slice::Iter`:
f0bab98695/src/libcore/slice.rs (L930-L937)
Using the `as_slice` method that was added in:
https://github.com/rust-lang/rust/pull/35447
This commit is contained in:
parent
f0bab98695
commit
bc52bdcedc
2 changed files with 17 additions and 0 deletions
|
@ -1713,6 +1713,15 @@ pub struct IntoIter<T> {
|
||||||
end: *const 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> {
|
impl<T> IntoIter<T> {
|
||||||
/// Returns the remaining items of this iterator as a slice.
|
/// Returns the remaining items of this iterator as a slice.
|
||||||
///
|
///
|
||||||
|
|
|
@ -501,6 +501,14 @@ fn test_into_iter_as_mut_slice() {
|
||||||
assert_eq!(into_iter.as_slice(), &['y', 'c']);
|
assert_eq!(into_iter.as_slice(), &['y', 'c']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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]
|
#[test]
|
||||||
fn test_into_iter_count() {
|
fn test_into_iter_count() {
|
||||||
assert_eq!(vec![1, 2, 3].into_iter().count(), 3);
|
assert_eq!(vec![1, 2, 3].into_iter().count(), 3);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue