我正在实现一个Rust应用程序,其中结构向量将被传递到闭包中。
#[derive(Clone, Copy)]
struct AttackInfo {
ppid: usize,
pname: &'static str,
cpu: f32,
}
type AList = Vec<AttackInfo>;
fn Task() {
let mut list: AList = AList::new();
// ...
// I fill up the list with many items
// ...
output.put(|msg| *msg = Some(Message::Value(list)));
}
output.put
是一个带闭包的函数,由库定义。
由于list
变量的错误:
cannot move out of captured outer variable in an `FnMut` closure
闭包将被执行多次,直到列表中的所有值都被清空。如何在不丢失变量范围的情况下发送列表数据?