Skip to content
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

Elaborate on destructuring syntax in match #554

Closed
ledoge opened this issue Mar 22, 2017 · 2 comments
Closed

Elaborate on destructuring syntax in match #554

ledoge opened this issue Mar 22, 2017 · 2 comments
Milestone

Comments

@ledoge
Copy link
Contributor

ledoge commented Mar 22, 2017

In the old version of the book, it is mentioned that : can be used to give a value a new name under 4.15. I found this misleading because it is never mentioned that : is just a part of the pattern that can also be used for testing values.

For the new book, I think it would be good to use a more complex example of destructuring and explain its syntax. I would have found an example like in this blog post very useful for understanding the possible uses:

       GuessState { answer: Answer::Bingo, guess: p, .. } => {
     // ~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~  ~~
     //     |                 |                 |     |
     //     |                 |                 |     Ignore remaining fields
     //     |                 |                 |
     //     |                 |      Copy value of field `guess` into local variable `p`
     //     |                 |
     //     |   Test that `answer field is equal to `Bingo`
     //     |
     //  Match against an instance of the struct `GuessState````
@nodakai
Copy link
Contributor

nodakai commented Apr 8, 2017

@carols10cents
Copy link
Member

@nodakai don't worry, @ledoge was just providing an example of what they were looking for. I found their example very helpful, and in the commit linked to this issue that I made before your comment, you'll see that we did not use the example with the ascii annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants