Skip to content

Commit

Permalink
Update an example of thread_local to use local_key_cell_methods (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 3, 2024
1 parent f6bd083 commit 6bc2415
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/subtyping.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,7 @@ thread_local! {
/// saves the input given into a thread local `Vec<&'static str>`
fn store(input: &'static str) {
StaticVecs.with(|v| {
v.borrow_mut().push(input);
})
StaticVecs.with_borrow_mut(|v| v.push(input));
}
/// Calls the function with it's input (must have the same lifetime!)
Expand All @@ -332,9 +330,8 @@ fn main() {
demo(&smuggle, store);
}
StaticVecs.with(|v| {
println!("{:?}", v.borrow()); // use after free 😿
});
// use after free 😿
StaticVecs.with_borrow(|v| println!("{v:?}"));
}
```

Expand Down

0 comments on commit 6bc2415

Please sign in to comment.