How do I create a static mutable hashmap? I am ok with unsafe code.
The normal static does not allow globals with constructors.
As an example, I want what is at https://gist.github.com/Kimundi/8782487 but HASHMAP to be mutable.
I understand that global shared mutable state is not what very rust-ish but I just want to know if such a thing is possible.
For maintained answers, see How do I create a global, mutable singleton?, as this question should have been marked as a duplicate.
Seeing as how you already have a solution for a global object that is non-mutable, perhaps you can use one of the cell
containers to add interior mutability?
Realistically, this sounds like a a bad idea. Global mutable state is problematic. Why can't you pass in a mutable hashmap to the methods / objects that need it?
You may also what to check out the implementation of stdin
, which provides safe access to a true global singleton.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With