-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enum example is very confusing #828
Comments
The one in match is a little better. It used to be mainly about body shape but that was deemed offensive though it made a little more sense. You can do something like this: enum Color {
Red,
Blue,
Green
}
enum Doors {
Two,
Four,
Other(i32)
}
enum Vehicle {
Boat(Color),
Car(Color, Doors),
Plane { color: Color, doors: Doors}
} Now the example is longer though. Is it much of a gain? The struct is always going to be a problem here because in this type of example, it is a stylistic choice chosen to differ from a tuple. Regardless, both advertise the main important characteristics of a enum: they can hold whatever you want in whatever order. FWIW, I don't see much advantage in splitting struct enums out into their own example strictly to show that enums can hold structs too. |
I can just about rationalise this if it's renamed to Would a real rust user write it this way? No idea. The example is match is a much better illustration. |
I just came here to open a ticket on this. Every time I want to demonstrate Rust enums to someone, I open up this chapter of Rust By Example, and then I have to apologize profusely for how terrible this example is. Maybe I'll open up a PR soon with a better example. |
I would love to see this fixed. |
http://rustbyexample.com/custom_types/enum.html
This suggests that a person is either:
I understand that it's hard to cram examples of all the ways you can use an enum into a single example enum, but maybe it could be split into multiple example types instead? The current example is confusing and doesn't reflect the way Rust developers use enums in the real world.
The text was updated successfully, but these errors were encountered: