-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Guide: Enums chapter contains unexplained match keyword #18169
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
Comments
You are correct. Nice catch! |
Are you ok with simply reordering them ? |
Maybe, if it flows okay, yeah. I do want to put SOME kind of mention of it first. |
It's probably easy to find out what let x = Value(5);
let y = Missing;
match x {
Value(n) => println!("x is {}", n),
Missing => println!("x is missing!"),
} In fact, I really don't know how the equivalent code without |
With an Option you coul unwrap I guess. By the way @steveklabnik why did you write a fake option enum ? |
Because we haven't talked about generics yet. |
Nicely done. However, my other concern, how this example could be done without |
@lgrahl I'm honestly not sure that it is possible with an arbitrary enum... Bt it's more an issue of sum types in general rather than a Rust issue (I can't find ways to do that in haskell nor in scala) |
@gamazeps Alright, I expected something like this as I was unable to figure out how to write it without |
@lgrahl Thanks a lot for the remark, it's exactly the kind of comment needed, if you see others don't hesitate to open new issues :) I'll try to add this tonight or tomorrow. |
internal: Disable GitHub releases for now These are currently throwing `Error: HttpError: Resource not accessible by integration` because of the organization change, let's disable them for today's release.
See: https://github.com/rust-lang/rust/blob/master/src/doc/guide.md#enums
The
match
keyword hasn't been introduced until that point but it's used in the code example which is confusing.I believe an if/else solution would be more explanatory, especially because the reader probably wants to see how to unpack the
Value
variant ofenum OptionalInt
. The same enum could then be used with thematch
keyword in the beginning of the next chapter (Match
).The text was updated successfully, but these errors were encountered: