News for hackers. Stuff that matters.
Re:Methods for Array Initialization in Rust (2018) by MauranKilom on Monday May 24, 2021 @09:12AM (#27263939)
Ok, but why was it the case?
Re:Methods for Array Initialization in Rust (2018) by ekidd on Monday May 24, 2021 @09:26AM (#27264056)
Rust has two low-level "array" types:

- &[Elem]: A "slice" of elements, represented as a pointer and a length.

- [Elem; N]. A fixed-size array where the number of elements is known at compile time. This might be used for 2D or 3D coordinates, for example.

Array slices have always supported arbitrary lengths. But arrays with fixed compile-time sizes are represented as entirely different types: it's an error to pass a [i32; 2] to a function that wants an [i32; 3]. The size of the fixed-size array is part of the type.

And until very recently, Rust's type system didn't support defining methods on [Elem; N] that were generic over N. This is a feature that tends to be added later in many languages that support generics, not just Rust.

Re:Methods for Array Initialization in Rust (2018) by rwmj on Monday May 24, 2021 @02:25PM (#27267913)
Thanks, I think this is the clearest explanation in the thread.