A std::Vec has a .len() method, but ExactSizeIterator is not implemented for it. This is inconvenient. Is this a design decision or just an omission (that could be fixed in a future Rust release)?
let vector = vec![3i32, 4, 5];
test(vector);
fn test(vector: impl ExactSizeIterator) {
println!("size is {}", vector.len());
}
results in a compile error:
the trait `ExactSizeIterator` is not implemented for `Vec<i32>`
Thanks for your nice, explanatory, answer, in retrospect this makes sense. At first sight it just seemed so logical for Vec to implement ExactSizeIterator...
Seemingly I need to explore the 'advanced' topics on generics (and iterators) a bit further..