Skip to content

Conversation

@manzaltu
Copy link

I believe that the explanation of listing 11 in chapter 1 is inaccurate (page 17). This includes the explanation for the hypothetical single-lifetime scenario in MutStr.
This PR includes a more accurate description of the issue.

Alternatively, listing 11-1 could be rewritten as:

struct MutStr<'a, 'b> {
    s: &'a mut &'b str,
}

fn main() {
    let mut s: &'static _ = "hello";
    *MutStr { s: &mut s }.s = "world";
}

with the explanation that, in a single-lifetime scenario, the above code would not compile (the println call is unnecessary). See the full explanation in the PR.

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