我的问题基本上是在我的程序中,我需要将对s
结构的引用传递到多个地方,包括一个新线程。例如,在 CI 中可以将其声明为全局结构并以这种方式使用它。我怎么能在生锈中做到这一点?
我还需要对一些代码使用RefCell
包装Rc
(我以前的问题)。
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 ... //
}