Tracking Issue for split_array · Issue #90091 · rust-lang/rust (original) (raw)
Feature gate: #![feature(split_array)]
This is a tracking issue for splitting slices and arrays into constant-length arrays.
Public API
impl<T, const N: usize> [T; N] { pub fn split_array_ref(&self) -> (&[T; M], &[T]); pub fn split_array_mut(&mut self) -> (&mut [T; M], &mut [T]);
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M]);
pub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M]);
}
Similar functions for slices have already been stabilized as:
impl [T] { pub const fn split_first_chunk(&self) -> Option<(&[T; N], &[T])>; pub fn split_first_chunk_mut(&mut self) -> Option<(&mut [T; N], &mut [T])>; pub const fn split_last_chunk(&self) -> Option<(&[T], &[T; N])>; pub fn split_last_chunk_mut(&mut self) -> Option<(&mut [T], &mut [T; N])>; }
See #111774
Unresolved Questions
- Naming, see Implement split_array and split_array_mut #83233 (review)
- Array functions should return
[T; N - M]
, like so:
impl<T, const N: usize> [T; N] { pub fn split_array(self) -> ([T; M], [T; N - M]); pub fn split_array_ref(&self) -> (&[T; M], &[T; N - M]); pub fn split_array_mut(&mut self) -> (&mut [T; M], &mut [T; N - M]); }
However, const generics is not powerful enough for this today. See #83233 (comment) and #83233 (comment).