Skip to content

The Rust Programming Language - 4.6 Loops issue #31334

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

Closed
theroseknight opened this issue Feb 1, 2016 · 2 comments · Fixed by #31344
Closed

The Rust Programming Language - 4.6 Loops issue #31334

theroseknight opened this issue Feb 1, 2016 · 2 comments · Fixed by #31344

Comments

@theroseknight
Copy link

The following code will not build or run. The issue is that 'lines' is never defined in this section of the book.

for (linenumber, line) in lines.enumerate() {
    println!("{}: {}", linenumber, line);
}
Outputs:

0: Content of line one
1: Content of line two
2: Content of line three
3: Content of line four

Rust is my first attempt to contribute to someone else's project so if I am not using these issues correctly please let me know and I will cease adding them as I go through the book.

@Aatch
Copy link
Contributor

Aatch commented Feb 1, 2016

The sample will run if you click the "Run" button that appears when you mouse over the sample. There is a lines variable defined, just hidden as it's not relevant there. In fact, showing a lines variable would probably be counter productive, as it could mislead readers not aware that it's just a stand-in for any arbitrary iterator.

To be honest, that section is a little sparse anyway and could probably do with a forward reference to the Iterators chapter along with a little more explanation.

@durka
Copy link
Contributor

durka commented Feb 1, 2016

There should probably be a "How to read this book" section that mentions the examples are clickable, and moreover automatically tested, so if you think it looks wrong, click Run to get a second opinion. It could also warn new Rustaceans about hidden lines in doctests (it's covered in the Documentation chapter, but that's too late) and tell them to watch out for it in the std docs too.

steveklabnik added a commit to steveklabnik/rust that referenced this issue Feb 1, 2016
steveklabnik added a commit to steveklabnik/rust that referenced this issue Feb 1, 2016
Fixes rust-lang#31334

This is just a quicker fix for this issue; since I'm working on the next draft of the book, I don't want to put a huuuge amount of work into improving it here.
steveklabnik added a commit to steveklabnik/rust that referenced this issue Feb 2, 2016
Fixes rust-lang#31334

This is just a quicker fix for this issue; since I'm working on the next draft of the book, I don't want to put a huuuge amount of work into improving it here.
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 a pull request may close this issue.

3 participants