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 &self when you only need to read data.
  • Use &mut self when you need to modify data.
  • Use self when you need to consume the instance.