Skip to content

Commit 2a20389

Browse files
committed
[T]::as_[mut_]slice
1 parent a197ebd commit 2a20389

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

library/core/src/slice/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4906,6 +4906,28 @@ impl<T> [T] {
49064906

49074907
if start <= self.len() && end <= self.len() { Some(start..end) } else { None }
49084908
}
4909+
4910+
/// Returns the same slice `&[T]`.
4911+
///
4912+
/// This method is redundant when used directly on `&[T]`, but
4913+
/// it helps dereferencing other "container" types to slices,
4914+
/// for example `Box<[T]>` or `Arc<[T]>`.
4915+
#[inline]
4916+
#[unstable(feature = "str_as_str", issue = "130366")]
4917+
pub const fn as_slice(&self) -> &[T] {
4918+
self
4919+
}
4920+
4921+
/// Returns the same slice `&mut [T]`.
4922+
///
4923+
/// This method is redundant when used directly on `&mut [T]`, but
4924+
/// it helps dereferencing other "container" types to slices,
4925+
/// for example `Box<[T]>` or `Arc<[T]>`.
4926+
#[inline]
4927+
#[unstable(feature = "str_as_str", issue = "130366")]
4928+
pub const fn as_mut_slice(&mut self) -> &mut [T] {
4929+
self
4930+
}
49094931
}
49104932

49114933
impl<T> [MaybeUninit<T>] {

0 commit comments

Comments
 (0)