I have a problem with lifetimes, it's really messing with my head and am hoping some of you nice Rustaceans can help me. imagine this sort of data structure:
type ListOneItems = Vec<ItemsOne>;
type ListTwoItems = Vec<ItemsTwo>;
type ListOneSubItems = Vec<SubItemsOne>;
type ListTwoSubItems = Vec<SubItemsTwo>;
struct Top {
first_list : ListOneItems,
second_list : ListTwoItems,
}
struct ItemsOne {
name : String,
subitems : ListOneSubItems,
}
struct SubItemsOne {
name : String,
// blah blah blah
}
struct ItemsTwo {
name : String,
reference_1 : &ItemsOne,
reference_2 : &ItemsTwo,
}
struct subItemsTwo {
name : String,
reference_1 : &SubItemsOne,
reference_2 : &SubItemsOne,
}
That is, the top level contains two lists of structs, each of those lists contains a list of structs and the second list (and sub items) contains references to specific items from the first list (so as not to save the same data twice in both lists).
As I try to set this up, I run into all sorts of confusion about how to set up the "lifetimes" properly.
If worse comes to worse, I can tag each of the things in the first list with a generated ID and then store the same ID in the second list, but that seems really inelegant.