Update an example of `thread_local` to use `local_key_cell_methods` (#438)

pull/439/head
Trevor Gross 10 months ago committed by GitHub
parent f6bd083c4c
commit 6bc2415218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -310,9 +310,7 @@ thread_local! {
/// saves the input given into a thread local `Vec<&'static str>` /// saves the input given into a thread local `Vec<&'static str>`
fn store(input: &'static str) { fn store(input: &'static str) {
StaticVecs.with(|v| { StaticVecs.with_borrow_mut(|v| v.push(input));
v.borrow_mut().push(input);
})
} }
/// Calls the function with it's input (must have the same lifetime!) /// Calls the function with it's input (must have the same lifetime!)
@ -332,9 +330,8 @@ fn main() {
demo(&smuggle, store); demo(&smuggle, store);
} }
StaticVecs.with(|v| { // use after free 😿
println!("{:?}", v.borrow()); // use after free 😿 StaticVecs.with_borrow(|v| println!("{v:?}"));
});
} }
``` ```

Loading…
Cancel
Save