What is the difference between iter and into_iter

iter() borrows elements for reading, while into_iter() takes ownership and consumes the collection.

Use iter() to borrow elements without moving them, and into_iter() to take ownership and move elements out of the collection.

let numbers = vec![1, 2, 3];

// Borrow: numbers is still usable after the loop
for n in numbers.iter() {
    println!("{n}");
}

// Move: numbers is consumed and cannot be used after the loop
for n in numbers.into_iter() {
    println!("{n}");
}