Method Calls: Mutable Borrow

Overview

Methods that take &mut self borrow the receiver mutably, allowing the method to change internal state without taking ownership.

Rust's method-call syntax automatically handles the needed referencing while preserving borrowing rules.

Official Rust Book: Method Syntax


Code example