News for hackers. Stuff that matters.
Re:Abstraction without overhead: traits in Rust by geofft on Monday May 11, 2015 @07:16PM (#9528492)
> Just go back to that tutorial with your C hat on and substitute the word "union" for "enum" and I promise it will all make sense. All your intuition about C unions will cross over just fine, and the new Rust rules (they're tagged at runtime and the compiler enforces that you can only ever use fields of a runtype-checked subtype) are straightforward extensions.

This is not true. Rust enums allow you to match on which of the types you have. C unions do not. If you want to implement a switch statement over the possible members of a C union, you need to put it inside a struct with a type field. You don't need to do so in Rust, and you can't do so and have it compile.

(That said, if your real complaint is that the official docs on enums are confusing, I'd certainly agree with that.)

Re:Abstraction without overhead: traits in Rust by steveklabnik on Monday May 11, 2015 @07:22PM (#9528511)
> (That said, if your real complaint is that the official docs on enums are confusing, I'd certainly agree with that.)

I'd love more specifics about which docs, if you have some time.

Re:Abstraction without overhead: traits in Rust by ajross on Tuesday May 12, 2015 @12:56PM (#9533105)
I hestiate to speak because everyone will turn it gray, but it's worth pointing out that the whole idea of enums having C-like "discriminants", which like four people have yelled at me about, is entirely missing from the book.

I had to go look it up in the reference, where it is sort of hidden too.

Re:Abstraction without overhead: traits in Rust by geofft on Tuesday May 12, 2015 @04:25PM (#9534603)
I just sent in this PR, is this helpful? https://github.com/rust-lang/rust/pull/25348

Specifically I ended up rewriting most of the enum page: https://github.com/geofft/rust/blob/trpl-fix-enums/src/doc/t...

I think there's more that can be done (e.g. the book doesn't document that if every variant of an enum is data-less, you can cast it to an integer), but hopefully this is a start.

Re:Abstraction without overhead: traits in Rust by geofft on Monday May 11, 2015 @09:58PM (#9529127)
trpl/enums.md is super weird, and also in the wrong order (the book documents enums before structs, and way before tuple structs, whereas enums are IMO easiest explained once you've already explained structs). I was going to send you a PR tomorrow or so. :)
Re:Abstraction without overhead: traits in Rust by steveklabnik on Monday May 11, 2015 @10:34PM (#9529242)
Fair enough. Tomorrow is basically the deadline before 1.0 though, so send it early :)