Hi all, I'm new in rust. Playing with "take_while" and "zip" i got an error.
fn main () {
let xs: [i32; 33] = [3; 33];
let fine: [i32; 32] = [3; 32];
let p = xs.iter().zip(&fine)
.take_while(|(x, y)| x == y)
.count();
dbg!(p);
let error: [i32; 33] = [3; 33];
let p = xs.iter().zip(&error)
.take_while(|(x, y)| x == y)
.count();
dbg!(p);
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0277]: `&[i32; 33]` is not an iterator
--> src/main.rs:11:23
|
11 | let p = xs.iter().zip(&error)
| ^^^ `&[i32; 33]` is not an iterator
|
= help: the trait `std::iter::Iterator` is not implemented for `&[i32; 33]`
= note: required because of the requirements on the impl of `std::iter::IntoIterator` for `&[i32; 33]`
error[E0599]: no method named `take_while` found for type `std::iter::Zip<std::slice::Iter<'_, i32>, &[i32; 33]>` in the current scope
--> src/main.rs:12:8
|
12 | .take_while(|(x, y)| x == y)
| ^^^^^^^^^^
|
= note: the method `take_while` exists but the following trait bounds were not satisfied:
`&mut std::iter::Zip<std::slice::Iter<'_, i32>, &[i32; 33]> : std::iter::Iterator`
`std::iter::Zip<std::slice::Iter<'_, i32>, &[i32; 33]> : std::iter::Iterator`
error: aborting due to 2 previous errors
Some errors occurred: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
Why can't I use an array containing more than 32 elements? With "fine" variable compile without error.