Currently the standard practice for code is to use slices as input arguments, even if it’s known that function must accept only fixed length input. One of the reasons for it is references to arrays (i.e. [T; 5]) can feel the second order citizens compared to slices, due to the traits being implemented only for sizes up to 32. This should be soon solved by this RFC. But other reason is that taking array references from an existing buffer is unergonomic and simply not possible in safe Rust.
Because of it existing code often omits important information from the API type signature, which can have negative impact on the performance and soundness of the code.
I would like to propose to add the second slicing type, the constant one. Essentially it will be a syntactic sugar to [
arrayref] (https://crates.io/crates/arrayref) crate macro and can look like
M required to be
usize constants (generic or
&foo must provide
[T]. As a result this expression will return
&[T; M-N], if
M > foo.len() or
N > M it will panic.
&foo[:M] will be equivalent to
N = 0 and
&foo[N:] will be allowed only if
foo is an array, so
M can be taken as
Syntax can be changed to something else to avoid possible ambiguity.
Leave everything as is. Teach about