We use the word "generic" in front of "lifetime parameters" because they are generic lifetime parameters.
The obvious counter-example is 'static
which is the only non-anonymous lifetime so we can refer to it outside of generic contexts. On the other hand, since all other possible lifetimes are anonymous the only way we can refer to them is through generic lifetime parameters.
The foo
function below can be called with theoretically infinitely many different possible lifetimes, and it works in all those situations because it's generic over lifetimes. Here's an example of calling it with 2 different lifetimes:
fn foo<'a>(x: &'a i32) -> &'a i32 { x }
fn main() {
foo(&1); // called with 'static lifetime
let x = 1;
foo(&x); // called with x's anonymous lifetime
// and so on
}
The lifetime-constraint relationship between the input argument and the output return type in both calls is the same but the lifetimes are different.
'a
generic as opposed to simply a parameter which takes various values (among them'static
). Are you saying'static
is a different type to the-lifetime-of-x ? In particular,foo
can be called with infinitely many arguments, not because it's generic overx
but because the parameterx
can be passed with infinitely many argument values. – Licking