In the following code I am getting the error:
error[E0277]: the size for values of type `[{integer}]` cannot be
known at compilation time at the line `for n in numbers[1..] {`
I did some searching around, but found nothing.
fn main() {
let mut numbers = Vec::new();
numbers.push(1);
numbers.push(32);
numbers.push(43);
numbers.push(42);
// ... And many more
println!("{:?}", numbers); // Sanity
let mut sum = 0;
// Problem code area
for n in numbers[1..] {
sum = sum + n;
}
// Problem code area
println!("{}", sum);
}
Also, the problem lines work if I replace them with following (adding & and * for ownership/borrowing and dereferencing)
for n in &numbers[1..] {
sum = sum + *n;
}
Why is the compilation failing in the former way?