Hi,
I was wondering why this simple little code doesn't compile and generare a lot of errors:
fn main() {
let array = [1, 2, 3];
for a in array {
println!( "{}", a);
}
}
While just changing array
with &array
(in the for
loop) it works without any problem.
Is it something related how the deference operator works with &array?
Thanks.
P.S.:
These are the errors generated by the little example code:
array.rs:4:5: 6:6 error: the trait `core::iter::Iterator` is not implemented for the type `[_; 3]` [E0277]
array.rs:4 for a in array {
array.rs:5 println!("{}", a);
array.rs:6 }
note: in expansion of for loop expansion
array.rs:4:5: 6:6 note: expansion site
array.rs:4:5: 6:6 note: `[_; 3]` is not an iterator; maybe try calling `.iter()` or a similar method
array.rs:4 for a in array {
array.rs:5 println!("{}", a);
array.rs:6 }
note: in expansion of for loop expansion
array.rs:4:5: 6:6 note: expansion site
array.rs:4:5: 6:6 error: the trait `core::iter::Iterator` is not implemented for the type `[_; 3]` [E0277]
array.rs:4 for a in array {
array.rs:5 println!("{}", a);
array.rs:6 }
note: in expansion of for loop expansion
array.rs:4:5: 6:6 note: expansion site
array.rs:4:5: 6:6 note: `[_; 3]` is not an iterator; maybe try calling `.iter()` or a similar method
array.rs:4 for a in array {
array.rs:5 println!("{}", a);
array.rs:6 }
note: in expansion of for loop expansion
array.rs:4:5: 6:6 note: expansion site
array.rs:4:5: 6:6 error: the trait `core::iter::Iterator` is not implemented for the type `[_; 3]` [E0277]
array.rs:4 for a in array {
array.rs:5 println!("{}", a);
array.rs:6 }
note: in expansion of for loop expansion
array.rs:4:5: 6:6 note: expansion site
array.rs:4:5: 6:6 note: `[_; 3]` is not an iterator; maybe try calling `.iter()` or a similar method
array.rs:4 for a in array {
array.rs:5 println!("{}", a);
array.rs:6 }
note: in expansion of for loop expansion
array.rs:4:5: 6:6 note: expansion site
error: aborting due to 3 previous errors