I have a .json
file with somewhat static data that I would like to use in both my front- and backend.
Of course I could parse and load the file dynamically in the backend on startup, but I would much rather generate a const struct in a build script based on that file instead, which would catch any errors in said file while building instead of at runtime.
But I am a little lost when it comes to generating rust code in a build script.
For example this .json
file:
{"a":1,"b":"test"}
Resulting in something like this:
struct JSONFileStruct {
a: i32,
b: &'static str
}
const JSONFILE: JSONFileStruct = JSONFileStruct { a: 1, b: "test" };