9.7 The self Parameter
9.7.1 Different Forms of self
self: Takes ownership of the instance.&self: Borrows the instance immutably.&mut self: Borrows the instance mutably.
9.7.2 Choosing the Right Form
- Use
&selfwhen you only need to read data. - Use
&mut selfwhen you need to modify data. - Use
selfwhen you need to consume the instance.