You donβt want the link to display exactly as much as the object. You just need to borrow on the object (perhaps shorter than the whole lifetime of the object), and you want the resulting link to have the lifetime of this borrowing. It is written like this:
pub fn get_foo<'a>(&'a self) -> &'a usize {
&self.foo
}
In addition, the elite of life makes the signature more beautiful:
pub fn get_foo(&self) -> &usize {
&self.foo
}
source
share