A mutable reference, written &mut in Rust, lets code modify a value through a borrow. Rust's borrow checker permits one active mutable reference, preventing overlap with immutable references and other mutable references. section 1.2.1
Use mutable references when modification should happen without taking ownership:
- Pass &mut when a function should modify existing data in place. section 5.4
- Treat exclusivity as a safety guarantee: mutable and immutable references cannot overlap, reducing unintended data races. section 1.2.1
- Inspect function inputs and outputs to estimate whether an operation mutates data, creates a copy, or passes ownership. section 5.4
Lowercase in place
An owned mutable string can be changed without returning a newly allocated string: fn lowercased_ascii(mut s: String) -> String { s.make_ascii_lowercase(); s } By contrast, to_lowercase takes an immutable reference and returns a new String, making a copy. Confirm performance-sensitive behavior in documentation and source code rather than relying only on signatures. section 5.4
Table 5.1 Examining Rust core string functions for copies (view table figure)
Compare string functions by their reference parameters, return types, and documented copy behavior. section 5.4


