Skip to content

Various fixes to improve clarity for explanations of structs & tuples, named-field/tuple-like structs, and a lifetime diagram.#4308

Open
JonathanMcCormickJr wants to merge 3 commits intorust-lang:mainfrom
JonathanMcCormickJr:main
Open

Various fixes to improve clarity for explanations of structs & tuples, named-field/tuple-like structs, and a lifetime diagram.#4308
JonathanMcCormickJr wants to merge 3 commits intorust-lang:mainfrom
JonathanMcCormickJr:main

Conversation

@JonathanMcCormickJr
Copy link
Copy Markdown

@JonathanMcCormickJr JonathanMcCormickJr commented Mar 29, 2025

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}");   //   |       |
                          //   |       |
}                         // --+-------+

@JonathanMcCormickJr JonathanMcCormickJr changed the title Clarifying language for defining the capabilities of tuples and structs to be inclusive of cases where they hold 0 or 1 value(s). Various fixes to improve clarity for explanations of structs & tuples, named-field/tuple-like structs, and a lifetime diagram. Apr 20, 2025
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 this pull request may close these issues.

1 participant