I think I outsmarted myself. I have a config object that I create with lazy_static.
lazy_static!{
pub static ref CONFIG: Config = Config::new().unwrap();
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub var1: usize,
pub var2: String,
// A whole lot more
}
impl Config {
pub fn new() -> Result<Config, Error> {
// I actually get the file name from args
let file = OpenOptions::new().read(true).open("model1.config")?;
let config: Config = serde_json::from_reader(file)?;
Ok(config)
}
}
In the rest of my code I can access configuration variables as CONFIG.var1
.
I just got a bug report from someone who didn't remember which configuration he used. I decided it might be a good idea to include CONFIG in our traces. That didn't work because CONFIG isn't Serialize. Next, I tried to print CONFIG to the console, but it isn't Display or Debug.
My solution is to re-read the config file in main.rs and add it to the trace file there. It seems there should be a better way.