When searching for documentation about conservative impl trait, I found this example:
struct A {
x: [(u32, u32); 10]
}
impl A {
fn iter_values<'a>(&'a self) -> impl 'a + Iterator<Item = u32> {
self.x.iter().map(|a| a.0)
}
}
What does the lifetime 'a
mean in the return type?
I am aware of this question about lifetime bound in Box
, but I think that the usecases are different. If I understand well the answer:
trait object is only valid for the lifetime 'a
It means that the trait object that lives somewhere in the heap will last during a lifetime 'a
.
But here, this is not a trait object but a concrete object that lives in the stack. So the compiler does not need to have hints about its lifetime.
What am I missing about this?