0

I've been working on a C++ game with a board and soldiers on it. My Player object has an array of pointers to his soldiers so that the player has quick access to his soldiers. The tricky thing is to sync them both to prevent issues.

How would you design something similar in Rust? I know there are raw pointers, but they are considered unsafe.

Is there a way to share an object between 2 classes so that one could read and one write? What about both read and write?

Shepmaster
  • 326,504
  • 69
  • 892
  • 1,159
  • Welcome to Stack Overflow! I believe your question is answered by the answers of [Situations where Cell or RefCell is the best choice](https://stackoverflow.com/q/30831037/155423), [Immutable reference after mutable borrow](https://stackoverflow.com/q/30882065/155423), [Mutable self while reading from owner object](https://stackoverflow.com/q/28385339/155423), [Mutating one field while iterating over another immutable field](https://stackoverflow.com/q/35936995). If you disagree, please [edit] your question to explain the differences. Otherwise, we can mark this question as already answered. – Shepmaster May 16 '18 at 16:14
  • Actually yes! Thanks a lot! :) – Amit Maimon May 16 '18 at 16:18
  • Are any of those more useful than the other? Are any not useful? I can mark up to 5 duplicates, but I'd prefer to order them most usefully. – Shepmaster May 16 '18 at 16:20
  • 1
    i think the first and the second are the most relevant ones. the others were a bit more complicated for me to understand with my knowledge. – Amit Maimon May 16 '18 at 17:16

0 Answers0