为什么Rust在将可变结构移入闭包后允许修改它?

时间:2018-04-09 20:06:45

标签: rust closures borrow-checker

是什么让以下代码能够编译?

#[derive(Debug)]
struct Abc {
    x: i32,
}

fn main() {
    let mut n = Abc { x: 20 };
    let c = &move || {
        println!("{:?}", n);
    };

    (*c)();
    n.x = 12; //-> But n is moved??
}

0 个答案:

没有答案