Hello everybody,
So I decided to start learning Rust, and because I like games, I thought it would be nice to try coding a text-based one. However, everytime I try something new, I always end fighting the borrow checker. My guess is that I'm structuring my code around an object-oriented architecture (because that's what I'm used to), and Rust has not been designed specifically for that.
I created a simplified version of my project that you can find here: Rust Playground.
I want the player to interact with the game by typing commands, like "go north", "eat apple", etc...
To accomplish this task, my game has a list of commands, that can receive extra arguments, (handled by what I called selectors.
These selectors return Selectable, which group everything that can be targetted by a command, such as a creature, an item, a direction, or even another command.
The main problem is that my commands and selectors need to have access to the game to be able to modify the world, or gather commands for instance. And then I start having troubles with references and lifetimes.
So, my question is somewhat general, but wat is wrong with my design, and what are your thoughts to organize such a project? I hope that the code I provided will help you understand my problem, because most of the questions I've read show very small code that doesn't do anything, so the answers are not really applicable. Are there any patterns I'm not aware of? Should I use Rc, clone or something else to get all the pieces communicate?
Thanks in advance for those of you who will read through my code and give me insights.
Kind regards,
Arnold