Lifetime of a lifetime?

I was reading through and saw the following:

  type Item = &'a &'a str;

What does this actually do/say? It looks like it's constraining lifetimes with two levels of indirection, but I have no idea what that would mean.

It's not lifetime of a lifetime, it's a pointer (with lifetime) to a pointer (with a lifetime) to str;

let x: String = "abc".to_string();
let y = &&x;


Well that's pretty obvious, now that you say it. Every time I read code with a lifetime syntax I haven't seen before I assume it's something entirely new and very complicated.

I should probably try to get out of that mindset. :slight_smile:


The lifetime is just an annotation. It says that both references share the same lifetime.

In the case of &'a &'b str neither reference shares the same lifetime (though this example does not specify how they overlap, it’s implied that 'b: 'a).


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.