file_check_macro

Crates.iofile_check_macro
lib.rsfile_check_macro
version0.1.0
sourcesrc
created_at2023-11-27 09:56:35.662576
updated_at2023-11-27 09:56:35.662576
descriptionA macro for checking the presence of a template file at compile time. E.g. for Tera templates
homepage
repository
max_upload_size
id1050292
size2,828
James Cole (jamescoleuk)

documentation

README

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:

  1. You're generating HTML on the server using, say, Tera.
  2. 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.
  3. You love that rusts checks everything, and you hate run-time errors.
Commit count: 0

cargo fmt