Skip to content

Commit

Permalink
Add [T; N]::as_[mut_]slice
Browse files Browse the repository at this point in the history
These methods are like the ones on `std::array::FixedSizeArray`
and in the crate `arraytools`.
  • Loading branch information
LukasKalbertodt committed Aug 30, 2020
1 parent 85fbf49 commit 104a023
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions library/core/src/array/mod.rs
Expand Up @@ -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
}
}

0 comments on commit 104a023

Please sign in to comment.