Hi Often times, I have the following pattern in code:
// A struct which owns some data and some references
struct Analysis<'f> {
cache: HashMap<&'f str, u64>
}
// A struct, which borrows Analysis
struct Codegen<'a, 'f: 'a> { // Note: I have to declare two lifetimes here
analysis: &'a Analysis<'f>, // This is what bothers me!
node_types: Vec<(Text<'f>, bool)>,
}
That is, I want to store a field of type Foo
, which also has a lifetime. So the field has two lifeimes: &'a Foo<'b>
, and I have to declare both lifetimes for the containing struct. Is it possible some how to parameterize the struct over a single lifetime instead? I would love something like this:
struct Codegen<'a> {
analysis: &'a Analysis<???>,
node_types: Vec<(Text<???>, bool)>,
}