I have a config that I want initialized on startup, but not have to re-read the file every time. To do this, I'm using lazy_static:
lazy_static! {
static ref SETTINGS: Settings = {
match Settings::init() {
Ok(c) => c,
Err(e) => panic!("{}", e),
}
};
}
But now I have a method that updates that config file, and I want to "re-initialize" / update it, without having to re-start the program.
pub fn save_config_file(data: &str) -> Result<String, Error> {
fs::write(CONFIG_FILE, data)?;
SETTINGS = {
match Settings::init() {
Ok(c) => c, // The line with the error
Err(e) => panic!("{}", e),
}
};
Self::read_config_file()
}
Which gives me the error: [rustc E0308] [E] mismatched types expected struct settings::SETTINGS, found struct settings::Settings
Is there any way to re-initialize a lazy_static? Or do I have to restart the program?