include_template!() { /* proc-macro */ }Expand description
Re-export proc macros from md-tmpl-macros so users can write
md_tmpl::include_template! instead of importing md_tmpl_macros separately.
Pre-parse and validate a .tmpl.md template at compile time and emit a
complete module.
§Syntax
include_template!("path/to/template.tmpl.md");
include_template!("path/to/template.tmpl.md" => custom_mod);When no custom name is given the module name is derived from the file stem
(e.g. greeting from greeting.tmpl.md).
§Generated module contents
pub fn template() -> &'static Template— the pre-compiled template singleton.pub struct Params { … }— typed parameter struct with:render()— zero-arg render using the embedded template.render_reloaded(tmpl)— render with a hot-reloaded template from disk.validate_template(tmpl)— check template compatibility.to_context()— convert to aContext.
- Sub-structs for compound types.
- Constants from the
consts:block. - Type aliases from the
types:block.
§Examples
extern crate md_tmpl_core as md_tmpl;
md_tmpl_macros::include_template!("prompts/simple_greeting.tmpl.md");
let output = simple_greeting::Params {
name: "World".into(),
}
.render()
.unwrap();
assert_eq!(output, "\nHello World!\n");§Panics
Panics if an env expression cannot be evaluated at macro expansion time.