Closed
Description
Given the following code:
fn main() {
let slice = [1,2,3,4];
let vec = vec![1,2,3,4];
println!("{} {} {}", slice.count(), vec.count(), vec.as_slice().count());
}
The current output is:
error[E0599]: the method `count` exists for array `[{integer}; 4]`, but its trait bounds were not satisfied
--> src/main.rs:5:32
|
5 | println!("{} {} {}", slice.count(), vec.count(), vec.as_slice().count());
| ^^^^^ method cannot be called on `[{integer}; 4]` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`[{integer}; 4]: Iterator`
which is required by `&mut [{integer}; 4]: Iterator`
`[{integer}]: Iterator`
which is required by `&mut [{integer}]: Iterator`
(repeated 3 times with slight variations)
Ideally the output should:
- suggest using
slice.len()
instead ofslice.count()
This is a common error, particularly for new users, and when switching between iterators and vectors/slices/arrays.