Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Rust has its share of random-feeling nonsense, like requiring PhantomData to "work around" unused type params, or that you can't compare arrays longer than 32 elements.


1. I've never had to use PhantomData since I started coding in rust pretty much fulltime 2 years ago. 2. You can compare arrays longer than 32, but the compiler will no longer create an automatic comparison for you. So it's not that you "can't" do it. -- That said, using == to compare >32 elements sounds inefficient, perhaps check your use-case?


It's not really a workaround (it didn't used to be required), it asks for PhantomData so it can figure out variance and infer auto traits.


Not comparing arrays longer than 32 elements by == sounds like a feature to me.


The 32-count cliff is not just for Eq - it also defeats niceties like Debug, Hash, Default. This isn't a deliberate design decision, it's due to a (current) limitation of Rust's value-type generics.

The point is to illustrate that when you WTF using Rust, sometimes it's not you, it really is Rust.


I think there are a few places were Rust didn't get it quite right, but this seems like a weird example. The 32 length limit is a temporary limitation, not a corner that Rust is painted into. Indeed, my understanding is that the limitation at this point is being maintained artificially due to an overabundance of caution (via https://doc.rust-lang.org/std/array/trait.LengthAtMost32.htm... ). That's not WTF, that's just TODO.


A great example of this can be seen writing any recursive data-structure such as a doubly linked list.


Which language doesn't.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: