Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rust 从Vec调用过程<;proc()->;uint>;_Rust - Fatal编程技术网

Rust 从Vec调用过程<;proc()->;uint>;

Rust 从Vec调用过程<;proc()->;uint>;,rust,Rust,在尝试回答时(已经有了一个很好的答案),我创造了以下代码: fn main() { let mut a : Vec<proc() -> uint>; for i in range(0u, 11) { a[i] = proc(){i}; } println!("{} {} {}", a[1](), a[5](), a[9]()); } 这个错误意味着什么?它不应该只返回uint?proc()是只能使用一次的闭包,因此调用它们 在您

在尝试回答时(已经有了一个很好的答案),我创造了以下代码:

fn main() {
    let mut a : Vec<proc() -> uint>;
    for i in range(0u, 11) {
        a[i] = proc(){i};
    }
    println!("{} {} {}", a[1](), a[5](), a[9]());
}
这个错误意味着什么?它不应该只返回
uint

proc()
是只能使用一次的闭包,因此调用它们


在您的情况下,这意味着将闭包移出
Vec
以使用它,这是不可能的,因为索引是对
&
指针的取消引用,它只允许不可变的访问。

啊,我明白了-
只能使用一次!谢谢
 <anon>:6:26: 6:30 error: cannot move out of dereference (dereference is implicit, due to indexing)
 <anon>:6     println!("{} {} {}", a[1](), a[5](), a[9]());