Skip to content

into_iter-moves-elements #1569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/fn/closures/closure_examples/iter_any.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ fn main() {
// `into_iter()` for vecs yields `i32`. No destructuring required.
println!("2 in vec2: {}", vec2.into_iter().any(| x| x == 2));

// `iter()` only borrows `vec1` and its elements, so they can be used again
println!("vec1 len: {}", vec1.len());
println!("First element of vec1 is: {}", vec1[0]);
// `into_iter()` does move `vec2` and its elements, so they cannot be used again
// println!("First element of vec2 is: {}", vec2[0]);
// println!("vec2 len: {}", vec2.len());
// TODO: uncomment two lines above and see compiler errors.

let array1 = [1, 2, 3];
let array2 = [4, 5, 6];

Expand Down