Skip to content

Commit b0559be

Browse files
authored
Rollup merge of rust-lang#72583 - CAD97:vec-iter-asref-slice, r=dtolnay
impl AsRef<[T]> for vec::IntoIter<T> Adds `impl<T> AsRef<[T]> for vec::IntoIter<T>`. This mirrors the same trait impl for [`slice::Iter`](https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html). Both types already offer `fn as_slice(&self) -> &[T]`, this just adds the trait impl for `vec::IntoIter`. If/when `fn as_slice(&self) -> &[T]` stabilizes for `vec::Drain` and `slice::IterMut`, they should get `AsRef<[T]>` impls as well. As thus, tangentially related to rust-lang#58957. My ultimate goal here: being able to use `for<T, I: Iterator<Item=T> + AsRef<[T]>> I` to refer to `vec::IntoIter`, `vec::Drain`, and eventually `array::IntoIter`, as an approximation of the set of by-value iterators that can be "previewed" as by-ref iterators. (Actually expressing that as a trait requires GAT.)
2 parents 8484b99 + 91f52a5 commit b0559be

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/liballoc/vec.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2628,6 +2628,13 @@ impl<T> IntoIter<T> {
26282628
}
26292629
}
26302630

2631+
#[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")]
2632+
impl<T> AsRef<[T]> for IntoIter<T> {
2633+
fn as_ref(&self) -> &[T] {
2634+
self.as_slice()
2635+
}
2636+
}
2637+
26312638
#[stable(feature = "rust1", since = "1.0.0")]
26322639
unsafe impl<T: Send> Send for IntoIter<T> {}
26332640
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)