我有一个不能更改的闭包,我需要在一个新线程中运行它,并且我需要向它传递一个变量.这是我想象的代码的样子:
use std::thread;
fn main() {
// I can not influence this closure, but this is what it looks like
let handle = move |data: i32| {
println!("Got {data}")
};
let foo = 123;
// This doesn't work
thread::spawn(handle).arg(foo).join()
}
在Python中等效的代码确实可以工作,所以我想知道在Ruust中这是否可能,如果是的话,那么是如何实现的.
提前谢谢您.