Skip to content

Commit 05090a9

Browse files
committed
[T]::as_[mut_]slice
1 parent 755c374 commit 05090a9

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
@@ -4893,6 +4893,28 @@ impl<T> [T] {
48934893

48944894
if start <= self.len() && end <= self.len() { Some(start..end) } else { None }
48954895
}
4896+
4897+
/// Returns the same slice `&[T]`.
4898+
///
4899+
/// This method is redundant when used directly on `&[T]`, but
4900+
/// it helps dereferencing other "container" types to slices,
4901+
/// for example `Box<[T]>` or `Arc<[T]>`.
4902+
#[inline]
4903+
#[unstable(feature = "thing_as_thing", issue = "none")]
4904+
pub const fn as_slice(&self) -> &[T] {
4905+
self
4906+
}
4907+
4908+
/// Returns the same slice `&mut [T]`.
4909+
///
4910+
/// This method is redundant when used directly on `&mut [T]`, but
4911+
/// it helps dereferencing other "container" types to slices,
4912+
/// for example `Box<[T]>` or `Arc<[T]>`.
4913+
#[inline]
4914+
#[unstable(feature = "thing_as_thing", issue = "none")]
4915+
pub const fn as_mut_slice(&mut self) -> &mut [T] {
4916+
self
4917+
}
48964918
}
48974919

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

0 commit comments

Comments
 (0)