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

Chapter 10-00 Listing 10-3: Usage of pattern matching in for loops #2277

Closed
digitalillusions opened this issue Feb 27, 2020 · 1 comment
Closed

Comments

@digitalillusions
Copy link

Hi, first of all I have to say I love the book. In my opinion its really well written and provides a nice introduction.

While reading I stumbled a little when the challenge was posed in Chapter 10-02 after listing 10-15, specifically the for loop, which reads:

    for &item in list.iter() {
        if item > largest {
            largest = item;
        }
    }

Specifically the line

for &item in list.iter() {

I do not remember coming across the concept of using an & in from of an item in a range based for loop in rust, even after asking some colleagues (who have worked with rust for nearly 3 years). I think this kind of destructuring or pattern matching should be mentioned at some point in the explaining text, maybe also with reference to Chapter 18-01. I might have missed it in my haste at some point, but explaining this also makes the explanation of the Copy trait a lot more obvious to me. I think this was already mentioned in #2121 although I think the focus there was on the copy trait.

Another thing that I noticed, was that while moving from Listing 10-3 to Listing 10-4 the code suddenly got extended from

for &item in list {

to

for &item in list.iter() {

Hope this can help to make the already amazing rust book a little better.

@steveklabnik
Copy link
Member

Hey there, thanks so much!

#2363 should have fixed this!

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

No branches or pull requests

2 participants