Safest way to make a serde_json result globally avaialable [duplicate]

痴心易碎 提交于 2020-12-26 05:19:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!