4 ms·
I'm not sure what you mean by standard collections, but BTreeMap is in Rust's standard library.
by correct_horse 7y ago
I'm not sure what you mean by standard collections, but BTreeMap is in Rust's standard library.
- pdpi 7y agoI think the point the GP is trying to make is that there’s no reason why BTreeMap couldn’t be an external crate, while only the core Go collections are allowed to be generic. A corollary to this is that adding more generic collections to Go’s standard library implies expanding the set of magical constructs.
- The_rationalist 7y agoRust has it's lot of weird hacks too. E.g array can take traits impls only if they have less than 32 elements... https://doc.rust-lang.org/std/array/trait.LengthAtMost32.html https://doc.rust-lang.org/std/array/trait.LengthAtMost32.htm...
- jolux 7y agoThat's a completely different and much more minor issue (red herring, more or less) than eschewing the one core language feature that makes performant type-safe custom data structures possible.
- steveklabnik 7y agoThis is purely temporary; it used to be less hacky, but in order to move to the no-hacks world, we had to make it a bit more hacky to start.
- masklinn 7y agoThat's… not that at all. You can absolutely implement traits for arrays of more than 32 elements[0]. It is rather that due to a lack of genericity (namely const generics) you can't implement traits for [T;N], you have to implement them for each size individually. So there has to be an upper bound somehow[1], and the stdlib developers arbitrarily picked 32 for stdlib traits on arrays. A not entirely dissimilar limit tends to be placed on tuples, and implementing traits / typeclasses / interfaces on them. Again the stdlib has picked an arbitrary limit, here 12[2], the same issue can be seen in e.g. Haskell (where Show is "only" instanced on tuples up to size 15). These are not "weird hacks", they're logical consequences of memory and file size not being infinite, so if you can't express something fully generically… you have to stop at one point. [0] here's 47 https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c523f6cf4ff4ff2e19adf79300d51567 https://play.rust-lang.org/?version=stable&mode=debug&editio... [1] even if you use macros to codegen your impl block [2] https://doc.rust-lang.org/src/core/fmt/mod.rs.html#2115 https://doc.rust-lang.org/src/core/fmt/mod.rs.html#2115
- kibwen 7y agoAlso worth noting that Rust's const generics support has progressed to the point that the stdlib is already using them to implement the standard traits on arrays; the 32-element issue still technically exists, but only because the stdlib is manually restricting the trait implementation so as to not accidentally expose const generics to stable Rust before const generics is officially stabilized.
- deleted 7y ago[deleted]
- zerr 7y agoIn Go, standard collections are compiler's magic while in Rust or e.g. C++ - they are implemented as libraries.