While trying to answer on Rust array of functions (it's been answered with a great answer), I've coined 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 proc
is being deprecated, I just figured out that this is what should be used instead of closures (I didn't know about move
and unboxed closures at that time).
However, I was not able to call elements of a vector due the following:
<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 this error means? Shouldn't it just return uint
?