minus-squareGobbel2000@feddit.detoRust@programming.dev•Question on holding related data in a struct.linkfedilinkarrow-up0·8 months agoI don’t think there is a good way of having references within the same struct, but you could store reference counted matches: matches: Vec<Rc<Match>>, players: HashMap<String, Rc<Match>>, You would still have to make sure that the players map is updated, maybe weak references are useful there. Maybe you could also consider storing the players of a match in the match itself, not outside. linkfedilink
I don’t think there is a good way of having references within the same struct, but you could store reference counted matches:
matches: Vec<Rc<Match>>, players: HashMap<String, Rc<Match>>,
You would still have to make sure that the
players
map is updated, maybe weak references are useful there.Maybe you could also consider storing the players of a match in the match itself, not outside.