Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: How to mutate a Thread Local RefCell?
/*
1. Why does the second println! output print LocalKey{ .. }
instead of the same output as the the first println! ?
2. If you remove the // below, why does it not compile ?
*/
use std::cell::RefCell;
use std::ops::DerefMut;
thread_local! {
static VEC: RefCell< Vec<f32> > = RefCell::new( vec![1.0, 2.0, 3.0] );
}
fn main() {
let v: RefCell< Vec<f32> > = RefCell::new( vec![1.0, 2.0] );
v.borrow_mut( ).deref_mut().push(3.0);
println!( "{:?}", v );
// VEC.borrow_mut( ).deref_mut().push(3.0);
println!( "{:?}", VEC );
}
3 posts - 2 participants
🏷️ rust_feed