Skip to content

Commit a846003

Browse files
authored
Switch lifetime and variable names so they are different (#2586)
This helps clarify that the lifetime and variables names do not need to match, but sticks to related themes (doc / document) for human clarity. As suggested by @fw-immunant in #2585 (review), which subsequently auto-merged.
1 parent 9c03d51 commit a846003

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/lifetimes/struct-lifetimes.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ enum HighlightColor {
1414
}
1515
1616
#[derive(Debug)]
17-
struct Highlight<'text> {
18-
slice: &'text str,
17+
struct Highlight<'document> {
18+
slice: &'document str,
1919
color: HighlightColor,
2020
}
2121
2222
fn main() {
23-
let text = String::from("The quick brown fox jumps over the lazy dog.");
24-
let noun = Highlight { slice: &text[16..19], color: HighlightColor::Yellow };
25-
let verb = Highlight { slice: &text[20..25], color: HighlightColor::Pink };
26-
// drop(text);
23+
let doc = String::from("The quick brown fox jumps over the lazy dog.");
24+
let noun = Highlight { slice: &doc[16..19], color: HighlightColor::Yellow };
25+
let verb = Highlight { slice: &doc[20..25], color: HighlightColor::Pink };
26+
// drop(doc);
2727
println!("{noun:?}");
2828
println!("{verb:?}");
2929
}
@@ -35,7 +35,7 @@ fn main() {
3535
underlying the contained `&str` lives at least as long as any instance of
3636
`Highlight` that uses that data. A struct cannot live longer than the data it
3737
references.
38-
- If `text` is dropped before the end of the lifetime of `noun` or `verb`, the
38+
- If `doc` is dropped before the end of the lifetime of `noun` or `verb`, the
3939
borrow checker throws an error.
4040
- Types with borrowed data force users to hold on to the original data. This can
4141
be useful for creating lightweight views, but it generally makes them somewhat

0 commit comments

Comments
 (0)