1 unstable release
0.1.0 | Nov 27, 2023 |
---|
#1041 in Procedural macros
3KB
file_check_macro
Use this macro to get compile time errors if a template doesn't exist.
The macro in this crate, generate_template
, takes a string slice (&str
). It checks that the file in the string exists on disk in src
, and generates a const TEMPLATE:&str = <your string slice;>
.
Usage:
This:
generate_template!("path/to/my/template.tera");
Is the same as:
const TEMPLATE:&str = "path/to/my/template.tera";
But with a check that the file exists at:
src/path/to/my/template.tera
Note the prepended src
.
The use case is this:
- You're generating HTML on the server using, say, Tera.
- You're a sensible person who knows that files that change together should live together. So you want to store your templates alongside their Rust handlers, not in some separate
templates
tree like some kind of blithering idiot. - You love that rusts checks everything, and you hate run-time errors.
Dependencies
~250–700KB
~17K SLoC