My problem basically is that in my program I need to pass around the reference to the s
struct to multiple places including a new thread. In C I could for example declare it a a global struct and use it that way.
How can I do this in rust?
I also need to use a RefCell
wrapped in Rc
for some code (my previous question).
fn a_thread(s: &SomeStruct) {
//... code using s reference ... //
}
struct SomeStruct {
val: bool,
}
fn main() {
let mut s = SomeStruct { val: true };
let s_rc = Rc::new(RefCell::new(s));
thread::spawn(move || a_thread(&s)); // <= error: use of moved value 's'
//... code using the s_rc ... //
}