I learn iterators and exactly speaking copied code below, and got error:
expected integer, found
&{integer}
let v = [1, 2, 3];
let mut iter = v.into_iter();
assert_eq!(Some(1), iter.next());
assert_eq!(Some(2), iter.next());
assert_eq!(Some(3), iter.next());
assert_eq!(None, iter.next());
Appreciate explanation what I do wrong, while copied code from documentation does not work. The error I got the every those lines:
assert_eq!(Some(1), iter.next());
assert_eq!(Some(2), iter.next());
assert_eq!(Some(3), iter.next());
Below information about rustc:
tomek@rhei-box:~/workspaces/rust-learn$ rustc --version
rustc 1.67.0 (fc594f156 2023-01-24)
Source: https://doc.rust-lang.org/std/iter/trait.IntoIterator.html#examples
>Solution :
Most likely you’re missing an edition key in your Cargo.toml since IntoIterator is only implemented for references to arrays for Rust versions prior to 1.54, therefore in editions before 2021 the IntoIterator implementation for arrays is hidden to preserve the semantics of older code, so to fix this you can add the following/replace the existing edition in your Cargo.toml:
[package]
//…
edition = "2021"