Skip to content

Commit

Permalink
Rollup merge of #72583 - CAD97:vec-iter-asref-slice, r=dtolnay
Browse files Browse the repository at this point in the history
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 #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.)
  • Loading branch information
RalfJung committed Jun 8, 2020
2 parents 8484b99 + 91f52a5 commit b0559be
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2628,6 +2628,13 @@ impl<T> IntoIter<T> {
}
}

#[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")]
impl<T> AsRef<[T]> for IntoIter<T> {
fn as_ref(&self) -> &[T] {
self.as_slice()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<T: Send> Send for IntoIter<T> {}
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down

0 comments on commit b0559be

Please sign in to comment.