How to create a global, mutable singleton in Rust?
Hi! I'm learning Rust and trying to make a global variable accessible from any part of the program that can be modified. For example, I need to store application configuration that is loaded once at startup and can later be updated.\n\nIn C++ or Python I would just make a global variable, but in Rust the compiler complains. Here's what I tried:\n\n```rust\nstatic CONFIG: Vec = Vec::new(); // error: missing lifetime\n```\n\nThen I tried `static mut`:\n\n```rust\nstatic mut COUNTER: i32 = 0;\n\nfn increment() {\n unsafe {\n COUNTER += 1;\n }\n}\n```\n\nThis works, but I was told that `static mut` is unsafe and can lead to data races. I've heard about `Mutex`, `OnceCell` and `lazy_static`, but I don't understand how to combine them correctly.