That would be because
Range<i32> is an
[i32]::iter() returns an
The reason for this discrepancy, in turn, is that iterating over a range consumes it (= destroys it), whereas iterating over an array does not consume it. If you do not consume the array, you can only return references to the elements, not move them away. Hence the
In an ideal world, you could consume the array and get an
Iterator<i32> just by calling
into_iter() on it instead of
iter(), as done on
Vec<i32>. Sadly, though, this implementation of
IntoIterator was not included in the Rust standard library back when the language was stabilized, and as far as I know it cannot be added in a backward-compatible way so we're unlikely to ever see it...
For small types like
i32, however, you can work around this by making inconsequential copies which will likely be optimized out by the compiler, via
[1, 2, 3].iter().cloned().