复制结构矢量

时间:2016-12-02 15:49:25

标签: rust closures

我正在实现一个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变量的错误:

,我无法发送list的值
cannot move out of captured outer variable in an `FnMut` closure

闭包将被执行多次,直到列表中的所有值都被清空。如何在不丢失变量范围的情况下发送列表数据?

0 个答案:

没有答案
相关问题