static compilation of an instance from json data in rust [duplicate]

Solution for static compilation of an instance from json data in rust [duplicate]
is Given Below:

I want to create a static instance at compile time (not runtime) from JSON data loaded from a file (similar to constexpr):

Example:

// 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?

You could use build.rs to generate Rust source code in OUT_DIR and include! it into the project.