I have this datastructure in Rust:
objects: [Object { ob: 1, id: 0 },
Object { ob: 1, id: 1 },
Object { ob: 0, id: 3 },
Object { ob: 0, id: 2 },
...
]
I'm using a HashMap where i can use the two keys "ob" and "id" to reference to data that im gonna store in this 2D HashMap. To create a 2D HashMap, i'm using the code found in this answer: How to implement HashMap with two keys?.
In the code below, i'm trying to firstly create all the structs (aCustomStructOfMine), and store them in the table with their belonging two keys, "ob" and "id". Then later in the code (not written yet), i will be accessing the structs iteratively and will be editing them and using their at-the-moment stored data.
fn analyse(objects: Vec<Object>) {
let mut table = Table::new();
for object in objects {
let ob = &object.ob;
let id = &object.id;
table.set(A(ob), B(id), aCustomStructOfMine::new());
}
}
I'm getting the following error:
borrowed value does not live long enough
assignment requires that `object.id` is borrowed for `'static`
How can i achieve the desired 2D HashMap from the given objects
variable.
I'm new to rust, and although i understand the basic principles of ownership, borrowing, lifetime and more, it's really hard to actually code with these concepts in mind.