about summary refs log tree commit diff
path: root/library/core/src/array
diff options
context:
space:
mode:
authorLukas Kalbertodt <lukas.kalbertodt@gmail.com>2020-08-30 20:22:09 +0200
committerLukas Kalbertodt <lukas.kalbertodt@gmail.com>2020-08-30 21:08:17 +0200
commit104a02301ca3cbc9f6056e9ebab8b928dad706af (patch)
treeb7e6272c784d90e8b56a399690b94bf75acd69b7 /library/core/src/array
parent85fbf49ce0e2274d0acf798f6e703747674feec3 (diff)
downloadrust-104a02301ca3cbc9f6056e9ebab8b928dad706af.tar.gz
rust-104a02301ca3cbc9f6056e9ebab8b928dad706af.zip
Add `[T; N]::as_[mut_]slice`
These methods are like the ones on `std::array::FixedSizeArray`
and in the crate `arraytools`.
Diffstat (limited to 'library/core/src/array')
-rw-r--r--library/core/src/array/mod.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs
index f85be5584e3..f45c99c285c 100644
--- a/library/core/src/array/mod.rs
+++ b/library/core/src/array/mod.rs
@@ -422,4 +422,17 @@ impl<T, const N: usize> [T; N] {
         // and we just need to cast it to the correct type.
         unsafe { crate::mem::transmute_copy::<_, [U; N]>(&dst) }
     }
+
+    /// Returns a slice containing the entire array. Equivalent to `&s[..]`.
+    #[unstable(feature = "array_methods", issue = "76118")]
+    pub fn as_slice(&self) -> &[T] {
+        self
+    }
+
+    /// Returns a mutable slice containing the entire array. Equivalent to
+    /// `&mut s[..]`.
+    #[unstable(feature = "array_methods", issue = "76118")]
+    pub fn as_mut_slice(&mut self) -> &mut [T] {
+        self
+    }
 }