I am writting plugin manager in rust, to see how it is possible to split rust based application into smaller decoupled modules.
At this point everything that I’ve done, is made in rust safe way, however now I have dilemma.
I have HashMap of containers, where each container is just a trait, that could return some container item by key.
I am implementing kind of lifecycle over set of container items, it means that according to criteria I have to build a list of container items from different containers, and iterate through this list couple time to send different events to the item.
Also I’ve borrowed mutable reference to the hash-map, and at this point rust guaranteed that no other thread or subroutine can read or mutate hash map, container and container items.
The issue that rust borrow checker, doesn’t allows me to take two mutable references to container that are stored in same hash-map, since I have only one mutable reference to hash-map. Same issue with references to multiple mut container items from single mut container.
Questions that I have:
- I need some simple solution for that. I don’t want go go to any over-engineering, but I still want to have this mutability. Please help me with any suggestion, how to solve this issue?
- In C++ which unsafe by default, seems it is not an issue if you know what you are doing. Should I use rust unsafe mut pointers for this case, or should I keep pushing safe way to solve this task?
- If it still not possible to write every algorithm in rust in safe way. Are there any good guideline for real enterprise and production systems where no time to think, which will describe when to use safe and unsafe code, which would be understandable for newcomers on the project, who came from Java, Go or C++?