tomplate!() { /* proc-macro */ }Expand description
Process templates at compile time with zero runtime overhead.
This macro can be used in two ways:
§Direct Template Invocation
Process a single template with parameters:
ⓘ
// From template registry (defined in .tomplate.toml files)
const QUERY: &str = tomplate!("user_query",
fields = "id, name, email",
table = "users"
);
// Inline template (when not found in registry)
const MSG: &str = tomplate!("Hello {name}!", name = "World");§Composition Block
Define multiple templates with shared local variables:
ⓘ
tomplate! {
// Local variables - reusable within block
let base_fields = tomplate!("id, created_at, updated_at");
// Export constants - available outside block
const USER_FIELDS = tomplate!("{base}, name, email",
base = base_fields
);
const POST_FIELDS = tomplate!("{base}, title, content",
base = base_fields
);
}
// Use the exported constants
println!("{}", USER_FIELDS);§Parameters
- First argument: Template name (from registry) or inline template string
- Named parameters:
key = valuepairs for template variables - Values can be literals or nested
tomplate!calls
§Template Resolution
- Checks if first argument matches a template name in registry
- If found, uses that template with its configured engine
- If not found, treats the string as an inline template using simple engine
§Examples
ⓘ
// Using different parameter types
const EXAMPLE: &str = tomplate!("my_template",
string = "text",
number = 42,
float = 3.14,
boolean = true,
nested = tomplate!("other", value = "data")
);
// Inline templates for quick use
const QUICK: &str = tomplate!(
"User: {name}, Status: {status}",
name = "Alice",
status = "active"
);