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.
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.
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: