I am trying to understand what T: 'a
means, where, I guess, T
is a type and 'a
is a lifetime.
I understand what 'a: 'b
means: x
('a
) outlives y
('b
) and so we cannot assign y
to x
in the following code
fn foo<'a, 'b, T>(mut x: &'a T, mut y: &'b T)
where 'a: 'b {
x = y; //compile time error
}
This reference book writes
T: 'a
means that all lifetime parameters ofT
outlive'a
.
But I am confused by the "all lifetime parameters of T
". What is a "lifetime parameter of (type?) T" ? I know that 'a
is a lifetime of x
in this signature fn foo<'a, T>(x: &'a T)
. Does it mean the same thing?
Could someone explain what T:'a
means by giving an example? I can't even imagine where we could use it and why.
struct Foo<'b, 'c> {bar: &'b str, boo: &'c [u8] }
. T:'a would mean that than calling foo::<Foo>() would guarantee that 'b and 'c are at least 'a – Chere