r/backtickbot • u/backtickbot • Dec 30 '20
https://np.reddit.com/r/learnrust/comments/knd3j7/global_config_best_practice/ghjtk8l/
I would only use a global config if you configuration is loaded when the program starts and does not change.
For this use case, once_cell is good. Specifically, you would want something like:
use once_cell::sync::Lazy;
static CONFIG: Lazy<Config> = Lazy::new(|| { /* Code to load config */ });If you need to be able to change the config but still have it be global, then you can make it a Lazy<Mutex<Config>>, but this type of global mutable state is generally discouraged.
0
Upvotes