this post was submitted on 25 Mar 2024
8 points (100.0% liked)
Rust
5744 readers
24 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I don't think there is a good way of having references within the same struct, but you could store reference counted matches:
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.
Thanks, the RC is a possible approach. It seems to violate DRY a bit but maybe there's no way around it.
The reason I had the players outside the match is that I need them there anyway, because when I get a player action I need to check in which match they are, who are their opponent(s) and so on. So even if they're in, they'll have to be out too as there are concurrent matches and the player actions come all through the same network stream.