5 ms·
What are you quoting? I can't find that in the article linked here and I don't understand what it's saying. Surely Rust didn't cap arrays at length 32?
by tgb 6y ago
What are you quoting? I can't find that in the article linked here and I don't understand what it's saying. Surely Rust didn't cap arrays at length 32?
- hctaw 6y agoMethods for arrays were capped at 32. So for example #[derive(Copy, Clone, Debug)] struct S { a: [i32; 33], } Would not compile, since Copy, Clone, and Debug were not implemented for arrays larger than 32.
- est31 6y agoNit: Copy has always been a builtin auto trait so it has always been implemented. You are right for the other traits. (also as other commenters point out, std builtin types like Clone etc have already been supporting larger array sizes because of the standard library's ability to use unstable features, but before const generics were available as an unstable feature, that restriction very much did exist, and now crates from the ecosystem can use it too).
- wyldfire 6y ago> If you'd like to learn more about const generics you can also check out the "Const Generics MVP Hits Beta" blog post for more information about the feature and its current restrictions. The article links to more details in that post [1], that's what the citation was from, sorry. I thought it was conspicuous that they had '32' in the example because I remembered it as a limitation before. No, arrays were not limited in length but IIRC generic types weren't able to make an array size generic across arbitrary counts. [1] https://blog.rust-lang.org/2021/02/26/const-generics-mvp-beta.html https://blog.rust-lang.org/2021/02/26/const-generics-mvp-bet...
- anchpop 6y agoArrays could be any length, but generic functions were only generic for arrays of length 32 or lower.
- exdsq 6y agoIf you think that’s crazy, check out the reason behind argument limits in scala. There’s just hard-coded Java functions like: func(a) func(a,b) Etc... some languages have really weird bit :)
- ibraheemdev 6y agoSide note: Argument limits are being removed in Scala 3.
- ibraheemdev 6y agoArray lengths were not limited. 32 was was just an arbitrary limit chosen for trait implementations for arrays as those were generated by macros.