The Rule of 3
There are three different ways to pass a value into a function: move it, pass by reference, and pass by mutable reference. We see this in method calls as self
, &self
, and &mut self
. This pattern of 3 appears in more places in Rust, including in iterators.
Let’s say we want to iterate over a Vec
, and then use it again. Perhaps we’d write some code like this:
Get hands-on with 1400+ tech skills courses.