4

I see signatures like:

fn get<'a>(&'a self, index: uint) -> &'a T

For a impl<T> Vec<T>, but I cannot find a clear explanation of the 'a part in the tutorial, the guide or the manual.

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
MichaelJones
  • 1,336
  • 2
  • 12
  • 22

1 Answers1

2

A 'a is a lifetime, representing that the returned &T reference is valid for (at least) as long as the self reference. This occurs when the returned reference points to memory owned by one of the input parameters (or points into a reference stored in the input parameters), with the named lifetime informing the compiler of the exact relationship by linking the references that have an "ownership connection".

Further information:

Community
  • 1
  • 1
huon
  • 94,605
  • 21
  • 231
  • 225
  • Just a note. The links in answer is broken and here's current (0.13 nightly) version of guide document: http://doc.rust-lang.org/guide-ownership.html – eonil Dec 23 '14 at 15:37