Skip to content

Commit e6510ba

Browse files
authored
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.)
2 parents 3d41252 + 738f848 commit e6510ba

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/liballoc/vec.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -2779,19 +2779,25 @@ impl<'a, T> Drain<'a, T> {
27792779
/// # Examples
27802780
///
27812781
/// ```
2782-
/// # #![feature(vec_drain_as_slice)]
27832782
/// let mut vec = vec!['a', 'b', 'c'];
27842783
/// let mut drain = vec.drain(..);
27852784
/// assert_eq!(drain.as_slice(), &['a', 'b', 'c']);
27862785
/// let _ = drain.next().unwrap();
27872786
/// assert_eq!(drain.as_slice(), &['b', 'c']);
27882787
/// ```
2789-
#[unstable(feature = "vec_drain_as_slice", reason = "recently added", issue = "58957")]
2788+
#[stable(feature = "vec_drain_as_slice", since = "1.46.0")]
27902789
pub fn as_slice(&self) -> &[T] {
27912790
self.iter.as_slice()
27922791
}
27932792
}
27942793

2794+
#[stable(feature = "vec_drain_as_slice", since = "1.46.0")]
2795+
impl<'a, T> AsRef<[T]> for Drain<'a, T> {
2796+
fn as_ref(&self) -> &[T] {
2797+
self.as_slice()
2798+
}
2799+
}
2800+
27952801
#[stable(feature = "drain", since = "1.6.0")]
27962802
unsafe impl<T: Sync> Sync for Drain<'_, T> {}
27972803
#[stable(feature = "drain", since = "1.6.0")]

0 commit comments

Comments
 (0)