book
book copied to clipboard
Various fixes to improve clarity for explanations of structs & tuples, named-field/tuple-like structs, and a lifetime diagram.
Fix 1:
Ch 5 -> 5.1. Defining and Instantiating Structs
The current version of this chapter reads that structs and tuples "both hold multiple related values." This language excludes those structs and tuples which happen to hold between 0-1 values. By inserting the word "can" into this, we can keep the emphasis on structs' and tuples' capacity for holding multiple sub-items, while still leaving room for the other cases to exist too.
Fix 2:
Ch 5 -> 5.1. Defining and Instantiating Structs Similarly, a later sentence in the same chapter currently reads "in a struct you’ll name each piece of data so it’s clear what the values mean." This language implies an obligation to name struct fields, excluding tuple structs. By replacing "you’ll" with "you can", we can be inclusive of tuple structs, while still emphasizing the power that comes with named fields.
Fix 3:
Ch 10 -> 10.3. Validating References with Lifetimes: -> The Borrow Checker
Listing 10-18 currently has a misleading diagram, as the end of the 'a lifetime is represented as ending before the ending of the 'b lifetime, when they actually both experience end-of-scope at the same point: the closing curly bracket. I've added a change to have this updated as well.
Before:
fn main() {
let x = 5; // ----------+-- 'b
// |
let r = &x; // --+-- 'a |
// | |
println!("r: {r}"); // | |
// --+ |
} // ----------+
After:
fn main() {
let x = 5; // ----------+-- 'b
// |
let r = &x; // --+-- 'a |
// | |
println!("r: {r}"); // | |
// | |
} // --+-------+