Skip to content

Commit 6bc2415

Browse files
authored
Update an example of thread_local to use local_key_cell_methods (#438)
1 parent f6bd083 commit 6bc2415

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/subtyping.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,7 @@ thread_local! {
310310
311311
/// saves the input given into a thread local `Vec<&'static str>`
312312
fn store(input: &'static str) {
313-
StaticVecs.with(|v| {
314-
v.borrow_mut().push(input);
315-
})
313+
StaticVecs.with_borrow_mut(|v| v.push(input));
316314
}
317315
318316
/// Calls the function with it's input (must have the same lifetime!)
@@ -332,9 +330,8 @@ fn main() {
332330
demo(&smuggle, store);
333331
}
334332
335-
StaticVecs.with(|v| {
336-
println!("{:?}", v.borrow()); // use after free 😿
337-
});
333+
// use after free 😿
334+
StaticVecs.with_borrow(|v| println!("{v:?}"));
338335
}
339336
```
340337

0 commit comments

Comments
 (0)