Avatar ·

What is the difference between iter() and into_iter() in Rust?

Hello colleagues! I started learning Rust and encountered confusion when working with iterators. In the documentation I see that collections (e.g., Vec) have methods iter() and into_iter(). At first glance they do the same thing — allow iterating over elements. But I noticed that after using into_iter() the original vector is no longer available, while after iter() it is still available. Why is that? Here's an example code that confuses me: ```rust fn main() { let numbers = vec![1, 2, 3]; // Using iter() for num in numbers.iter() { println!("{}", num); } println!("Vector after iter(): {:?}", numbers); // Works! // Using into_iter() let numbers2 = vec![4, 5, 6]; for num in numbers2.into_iter() { println!("{}", num); } // print