Skip to content

Archive

Iterators

1 articles
Rust 02 Sep 2026 4 min read

Rust Iterator Ownership: iter, iter_mut, and into_iter

Rust iteration becomes much easier once iterator choice is connected to ownership. For a collection such as Vec<T>, the central question is whether the loop should borrow values, mutate them in place, or consume the collection. The common methods are iter(), iter_mut(), and into_iter(). Borrow with iter() iter() produces shared references: fn print_names(names: &[String]) { for name in names.iter() { println!("{name}"); } } Inside the loop, name has type &String.