I'm trying to created "nested contexts" that work like prototype inheritance: if a value can't be found in the child, it will be looked up in the parent. Therefore I have a struct that looks like this:
Essentially, lifetime in LookupContext<'a> is the exact same as in declaration of a struct. Because you said:
struct LookupContext<'a> {
You also needed to say this later on.
name: LookupContext<'some_lifetime>,
The same applies to generic types too, for instance.
struct HashMap<K, V> {
Requires you to say for instance this.
map: HashMap<String, i32>,
Note that Rust can get rid of lifetimes in specific situations in function declarations, but that only applies to function declarations (not structs). For instance, instead of writing this.
fn something<'a>(name: &'a str) -> &'a str {
You can write this.
fn something(name: &str) -> &str {
This works when:
there are no types with lifetimes on output side
there is a single type which requires lifetime on input side (then it's used for all outputs)
there is &self or &mut self argument (then its lifetime is used for all outputs)