diff options
| author | Ralf Jung <post@ralfj.de> | 2020-06-08 09:55:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-08 09:55:20 +0200 |
| commit | b0559bebd800b763700063a6610f6416ea5679c0 (patch) | |
| tree | cd879799beb234464da4076fc7042a63f8efcdea /src/liballoc | |
| parent | 8484b9935c4d0a8e2209511a0094cc92ba09f561 (diff) | |
| parent | 91f52a51a23f8c5e8c82c49bbf3ab1bb781d3b02 (diff) | |
| download | rust-b0559bebd800b763700063a6610f6416ea5679c0.tar.gz rust-b0559bebd800b763700063a6610f6416ea5679c0.zip | |
Rollup merge of #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 #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.)
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/vec.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 96923ea47f3..9c775eef6a8 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -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")] |
