I am in need of a mutable global
BTreeMap. I’ll tell why so that if there is alternative then you can tell. Every operation that happens in my crate depends on finally getting or putting information onto the network. The networking crate is not yet ready. So i just made a mock backend that will mimic networking but actually use this global BTreeMap to give an illusion of data being stored persistently in the network. I need all tests in all modules to use that global Map indirectly through the mock. For instance, every unit test needs to start out by creating an account. This account name cannot be repeated and has to be randomly generated. So if any test uses same name for the account creation i have to flag it as an error, hence need persistence across all tests (which i guess rust runs in parallel). So when actual network is up, the testing will happen in CI (travis, jenkins etc) against that network and no extra code/test will be required and no existing ones will be modified.
So is there a way i can do something like:
static mut DATA_STORE: ::std::sync::Mutex<::std::collections::BTreeMap<SomeType, Vec<u8>>> = ::std::sync::Mutex::new(::std::collections::BTreeMap::new());
ofcourse the usage will require
unsafe blocks but i am fine with it as just one mod (the mock backend) will be using it and other mods just use this mock - so other mods will not have access to
DATA_STORE (they don’t even know and believe it is gone into the network)