问题
What is a safe way to make a serde_json result globally available in rust?
For instance I have a pub function in a module that contains
let contents = fs::read_to_string(json_file_path).expect("file not found");
let myVar: Foo = match serde_json::from_str(&contents){ ...}
println!("WIDTH:{}", myVar.Output.width);
static mut myStaticVar: String = myVar; // <- Error: attempt to use a non-constant value in a constant
How would I make the myVar.Output.width
variable available to be read by a public function in another module?
Trying to assign myVar to a static mut
fails with Error: attempt to use a non-constant value in a constant
来源:https://stackoverflow.com/questions/65187240/safest-way-to-make-a-serde-json-result-globally-avaialable