diff options
| author | Ralf Jung <post@ralfj.de> | 2020-06-15 09:57:26 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-15 09:57:26 +0200 |
| commit | e6510babc786469075f76db94fedfe651072bf25 (patch) | |
| tree | 73103aa06ba2f5d620b24f62d4ce3d255a74b985 /src/liballoc | |
| parent | 3d41252fcc28d9da1005f3207462e95006c232e4 (diff) | |
| parent | 738f8487fd78a7d860be4e65eee85c9a0e957c13 (diff) | |
| download | rust-e6510babc786469075f76db94fedfe651072bf25.tar.gz rust-e6510babc786469075f76db94fedfe651072bf25.zip | |
Rollup merge of #72584 - CAD97:stabilize-58957, r=dtolnay
Stabilize vec::Drain::as_slice and add `AsRef<[T]> for Drain<'_, T>`. Tracking issue: #58957. Does not stabilize `slice::IterMut::as_slice` yet. cc @cuviper This PR proposes stabilizing just the `vec::Drain::as_slice` part of that tracking issue. 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 | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 2226737757b..06462fd96d9 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2779,19 +2779,25 @@ impl<'a, T> Drain<'a, T> { /// # Examples /// /// ``` - /// # #![feature(vec_drain_as_slice)] /// let mut vec = vec!['a', 'b', 'c']; /// let mut drain = vec.drain(..); /// assert_eq!(drain.as_slice(), &['a', 'b', 'c']); /// let _ = drain.next().unwrap(); /// assert_eq!(drain.as_slice(), &['b', 'c']); /// ``` - #[unstable(feature = "vec_drain_as_slice", reason = "recently added", issue = "58957")] + #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] pub fn as_slice(&self) -> &[T] { self.iter.as_slice() } } +#[stable(feature = "vec_drain_as_slice", since = "1.46.0")] +impl<'a, T> AsRef<[T]> for Drain<'a, T> { + fn as_ref(&self) -> &[T] { + self.as_slice() + } +} + #[stable(feature = "drain", since = "1.6.0")] unsafe impl<T: Sync> Sync for Drain<'_, T> {} #[stable(feature = "drain", since = "1.6.0")] |
