The answer "in general" (about saving a hash table that is mutable when used together) is that it is not directly possible; Rust was specifically designed to prohibit sharing a mutable state, to avoid certain types of errors and to protect certain types of security (and for other reasons).
However, you can create something similar to a common modified hash table. Imagine that one task has a mutable hash table. You can write the code so that other tasks can send him messages that said: "Update the hash table so that 5 maps to 18" or "Tell me that there are 7 maps."
What does this indirection do? Firstly, by copying values ββinto messages, it is impossible for another task to trample all the memory that you find in the middle of reading (a big security problem), and secondly, by writing code indirectly, it is more clear to the programmer that it is and is not atomic operation; the programmer will know that one should not expect that two consecutive messages about the contents of the hash table do not necessarily refer to the same version of the hash table, an assumption that is perfectly true (at least in Rust, due to some other restrictions) about two consecutive reads from an unpartitioned, mutable hash table.
source share