evestera / json_typegen

Tools and libraries to create types for Rust, Kotlin, TypeScript and Python from JSON samples
https://typegen.vestera.as
Apache License 2.0
268 stars 26 forks source link

Use `include_str!` to trigger recompile when sample file changes #35

Open evestera opened 2 years ago

evestera commented 2 years ago

When reading sample from file using the procedural macro (e.g. json_typegen!("Point", "point.json")), if the sample file changes the compiler will not be aware that anything relevant has changed and so will not recompile.

There is a hack we can do to let the compiler know we are using a file. Output code like this in addition to the actual code:

const _: &'static str = include_str!("point.json");

Tracking issue for better way to do this (from which the snippet above was taken): https://github.com/rust-lang/rust/issues/73921