From 6bc2415218d4dd0cb01433d8320f5ccf79c343a1 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 2 Jan 2024 22:01:04 -0600 Subject: [PATCH] Update an example of `thread_local` to use `local_key_cell_methods` (#438) --- src/subtyping.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/subtyping.md b/src/subtyping.md index f63b532..4c45b2d 100644 --- a/src/subtyping.md +++ b/src/subtyping.md @@ -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!) @@ -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:?}")); } ```