Skip to content

Commit 104a023

Browse files
Add [T; N]::as_[mut_]slice
These methods are like the ones on `std::array::FixedSizeArray` and in the crate `arraytools`.
1 parent 85fbf49 commit 104a023

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/core/src/array/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,17 @@ impl<T, const N: usize> [T; N] {
422422
// and we just need to cast it to the correct type.
423423
unsafe { crate::mem::transmute_copy::<_, [U; N]>(&dst) }
424424
}
425+
426+
/// Returns a slice containing the entire array. Equivalent to `&s[..]`.
427+
#[unstable(feature = "array_methods", issue = "76118")]
428+
pub fn as_slice(&self) -> &[T] {
429+
self
430+
}
431+
432+
/// Returns a mutable slice containing the entire array. Equivalent to
433+
/// `&mut s[..]`.
434+
#[unstable(feature = "array_methods", issue = "76118")]
435+
pub fn as_mut_slice(&mut self) -> &mut [T] {
436+
self
437+
}
425438
}

0 commit comments

Comments
 (0)