macro_rules! register_templates {
{
$(
extra = { $( $extra_template:expr ),* $(,)? };
)?
$(
// Match any attribute on the function, such as #[doc], #[allow(dead_code)], etc.
$( #[ $attr:meta ] )*
// The function name
pub fn $name:ident
// Optional list of generics. Taken from
// https://newbedev.com/rust-macro-accepting-type-with-generic-parameters
$(< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)?
// Type of context taken by the template
( $param:ty )
{
// The name of the template file
$template:expr
}
)*
} => { ... };
}
Expand description
Macro that helps generating helper function that renders a specific template with a strongly-typed context. It also register the template in a static array to help detecting missing templates at startup time.
The syntax looks almost like a function to confuse syntax highlighter as little as possible.