Skip to content

Archive

Borrowing

2 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.

Rust 02 Sep 2026 4 min read

Interior Mutability in Rust with RefCell

Rust normally enforces borrowing at compile time: either one mutable reference or any number of immutable references may exist at a given moment. That rule prevents data races and many aliasing bugs before the program runs. Sometimes the compiler cannot prove that a safe mutation pattern is valid, even though the program can enforce the rule dynamically. RefCell<T> provides interior mutability for those cases by moving borrow checking from compile time to runtime.