Methods

Methods are annotated similarly to functions:

  1. struct Owner(i32);
  2. impl Owner {
  3. // Annotate lifetimes as in a standalone function.
  4. fn add_one<'a>(&'a mut self) { self.0 += 1; }
  5. fn print<'a>(&'a self) {
  6. println!("`print`: {}", self.0);
  7. }
  8. }
  9. fn main() {
  10. let mut owner = Owner(18);
  11. owner.add_one();
  12. owner.print();
  13. }

See also:

methods