From 104a02301ca3cbc9f6056e9ebab8b928dad706af Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Sun, 30 Aug 2020 20:22:09 +0200 Subject: [PATCH 1/2] Add `[T; N]::as_[mut_]slice` These methods are like the ones on `std::array::FixedSizeArray` and in the crate `arraytools`. --- library/core/src/array/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index f85be5584e3f1..f45c99c285c84 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -422,4 +422,17 @@ impl [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 + } } From d7afe2a223ab0a118bcdae39e8e2affbccaa61ae Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Sun, 30 Aug 2020 21:07:23 +0200 Subject: [PATCH 2/2] Fix tests using `FixedSizeArray` methods (which are now shadowed) --- library/core/tests/lib.rs | 1 + library/core/tests/option.rs | 1 - library/core/tests/result.rs | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 81e621318e141..4a651e5aa0ee3 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -1,5 +1,6 @@ #![feature(alloc_layout_extra)] #![feature(array_chunks)] +#![feature(array_methods)] #![feature(array_map)] #![feature(bool_to_option)] #![feature(bound_cloned)] diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs index fa308160fc228..b46bcfd16d283 100644 --- a/library/core/tests/option.rs +++ b/library/core/tests/option.rs @@ -1,4 +1,3 @@ -use core::array::FixedSizeArray; use core::clone::Clone; use core::mem; use core::ops::DerefMut; diff --git a/library/core/tests/result.rs b/library/core/tests/result.rs index caa2d916cd7a8..35598295a9515 100644 --- a/library/core/tests/result.rs +++ b/library/core/tests/result.rs @@ -1,4 +1,3 @@ -use core::array::FixedSizeArray; use core::ops::DerefMut; use core::option::*;