book
book copied to clipboard
Fix confusing prose in Ch2 due to RFC2795
The tutorial code was changed due to RFC2795, but the prose following it introducing format string was not, and was confusing as a result. This commit clarifies the current syntax, introducing both the RFC2795 syntax for identifiers and the empty pincer syntax for expressions.
I like this changes. However, beginners will probably think this is the only way to print out a value. They might not know that these two lines are doing the same thing.
println!("You guessed: {guess}");
println!("You guessed: {}", guess);
They might think the first one is valid but the second one is not.
A little bit off-topic, but close enough that it might be worth considering in the context of these changes: it could also be helpful to include a note about a minimum version requirement / having to update if an error compilation error is encountered relating to this syntax.
I tried compiling the guess game code with rust 1.57 without realizing it and got a compilation error:
❯ cargo run
Compiling guessing_game v0.1.0 (/tmp/guessing_game)
error: there is no argument named `guess`
--> src/main.rs:14:28
|
14 | println!("You guessed: {guess}");
| ^^^^^^^
error: could not compile `guessing_game` due to previous error
For new users starting with a fresh Rust install, this likely won't be an issue, but for users with older installations, this could come up.
I have a slightly different fix for this that I've made as part of checking copy-editing for a new print version, but I'm not going to have time to merge it in for the next few weeks.
include a note about a minimum version requirement
There's a note in the beginning of the book (and the landing page of the online book) about minimum Rust version assumptions. There are a lot of places where one could get an error if you're on an older Rust version, I'm not able to handle all of them throughout the book.
Okay that's completely fair -- I did fly over that section without even thinking to stop and check.. That's on me. Thanks for taking the time to put together and maintain this great resource, and for making it free to the community! So far, the experience learning Rust has been very positive :)
Ultimately superseded by the changes @carols10cents made for the most recent changes from the print edition a couple years ago, so closing this out. Thanks again, though!