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());
}
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8bd1115b12adc0eb5feb16bbb63a06cb
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 of slice.count()
This is a common error, particularly for new users, and when switching between iterators and vectors/slices/arrays.
Given the following code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8bd1115b12adc0eb5feb16bbb63a06cb
The current output is:
(repeated 3 times with slight variations)
Ideally the output should:
slice.len()instead ofslice.count()This is a common error, particularly for new users, and when switching between iterators and vectors/slices/arrays.