Skip to content

Guide: explains the enum/match relationship #18497

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

Merged
merged 1 commit into from
Nov 4, 2014

Conversation

gamazeps
Copy link
Contributor

Closes #18169

GoodGuy(string),
BadGuy(string),
Peon,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lacks closing backticks.

@steveklabnik
Copy link
Member

Thanks for taking some initiative on this!

and can be even more useful when they're generic across types. But before we get to
generics, let's talk about how to use them with pattern matching, a tool that will
let us deconstruct this sum types in a very elegant way (a classic in funtional
programing) and avoid all these messy `if/else`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/programing/programming/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Add `s.`
s/`if/else`/`if/else`s./`

@gamazeps
Copy link
Contributor Author

gamazeps commented Nov 3, 2014

Updated :)

What do you think @steveklabnik ?

}
```

And that is how you handle enums, and thus can use the value contained in the.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contained in the.... is followed by?

@gamazeps
Copy link
Contributor Author

gamazeps commented Nov 4, 2014

@mdinger corrected :) (damn you spaces before punctuation, you are the exact opposite in French...)

```
Where a `Result` is either an `OK`, with a result of a computation, or an `ErrorReason`
with a `String` explaining what caused the computation to fail. This enum is actually
very useful as you can guess and is even a part of the standard library.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea, but naming it Result introduces shadowing. This is why I made the previous one OptionalInt. Can we maybe do something similar here?

Also the 'as you can guess' makes this flow a little awkward to me.

I do think this is a significnatly better example, thank you :)

@steveklabnik
Copy link
Member

This just keeps getting better. I have a few more things, but they're all very small, and I'm really happy with how this is turning out.

@gamazeps
Copy link
Contributor Author

gamazeps commented Nov 4, 2014

@steveklabnik edited :)

@steveklabnik
Copy link
Member

Wonderful, thank you so much!

bors added a commit that referenced this pull request Nov 4, 2014
@bors bors closed this Nov 4, 2014
@bors bors merged commit dc7c8da into rust-lang:master Nov 4, 2014
@gamazeps gamazeps deleted the enumsmatch branch May 7, 2017 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Guide: Enums chapter contains unexplained match keyword
8 participants