Procedure call from Vec <proc () & # 8594; uint>
While trying to answer an array of Rust functions (which has been answered excellently), I came up with the following code:
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]());
}
Please ignore the fact that it is proc
deprecated, I just realized that this is what should be used instead of closures (I was not aware of move
and unpacked closures at this time).
However, I was unable to call the elements of the vector due to the fact that:
<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]());
What does this error mean? Shouldn't it return uint
?
+3
source to share