Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

expected integer, found `&{integer}`

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading