我想在编译时(不是运行时)从文件加载的 JSON 数据创建一个静态实例(类似于 constexpr):
例子:
// a file in the project /path/to/project/data.json
{
"field1" : "a"
}
// project code:
use serde_json::json;
struct MyStruct {
field1: String
}
// this is what I have, created at runtime
let json = json!(include!("data.json"));
let instance = serde_json::from_value::<MyStruct>(json);
// what I want:
// compile checked and created "statically"
let compiled_instance : MyStruct = static_instance_from_file!("data.json"); // how can this be verified by the compiler?