I am working on a small open-source game. Most of the server- and networking-logic is written in Elixir, but the actual game logic is written in Rust.
However, to not cheat with the immutable nature of the data structures that are used under the hood in the Rust code, I would like to use persistent data structures instead of mutable ones such that even though these structures are opaque from the Elixir side, passing the same opaque value twice to a ‘render’ Rust function twice should result in the same output.
For persistent lists, vectors, sets and maps, there is the great rpds library.
But now I have the issue that I would like my actual game state struct to become a persistent data structure.
I see te following possibilities:
- Don’t do it, only have the members of the struct be persistent data structures and create a new copy of the main game state struct every time one of its fields is changed.
- Emulate the struct as a RPDS map. This would mean that the different fields of the struct are now strings whose existence is no longer checked by the compiler.
- Write custom logic to make it persistent.
What to do?