Skip to content

Commit

Permalink
Rollup merge of rust-lang#82771 - emilio:iter-mut-as-slice, r=m-ou-se
Browse files Browse the repository at this point in the history
slice: Stabilize IterMut::as_slice.

Much like rust-lang#72584.

As per rust-lang#58957 there's no blocker for this, and I wanted to use this
today :-)

Closes rust-lang#58957
  • Loading branch information
Dylan-DPC committed Mar 21, 2021
2 parents c19664d + 2bd7c1b commit ca8d13d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions library/core/src/slice/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ impl<'a, T> IterMut<'a, T> {
/// Basic usage:
///
/// ```
/// # #![feature(slice_iter_mut_as_slice)]
/// let mut slice: &mut [usize] = &mut [1, 2, 3];
///
/// // First, we get the iterator:
Expand All @@ -299,12 +298,19 @@ impl<'a, T> IterMut<'a, T> {
/// // Now `as_slice` returns "[2, 3]":
/// assert_eq!(iter.as_slice(), &[2, 3]);
/// ```
#[unstable(feature = "slice_iter_mut_as_slice", reason = "recently added", issue = "58957")]
#[stable(feature = "slice_iter_mut_as_slice", since = "1.53.0")]
pub fn as_slice(&self) -> &[T] {
self.make_slice()
}
}

#[stable(feature = "slice_iter_mut_as_slice", since = "1.53.0")]
impl<T> AsRef<[T]> for IterMut<'_, T> {
fn as_ref(&self) -> &[T] {
self.as_slice()
}
}

iterator! {struct IterMut -> *mut T, &'a mut T, mut, {mut}, {}}

/// An internal abstraction over the splitting iterators, so that
Expand Down

0 comments on commit ca8d13d

Please sign in to comment.