| Crates.io | tron |
| lib.rs | tron |
| version | 2.1.0 |
| created_at | 2025-01-16 05:51:29.173133+00 |
| updated_at | 2025-09-11 22:55:27.213962+00 |
| description | A rust based template system built for speed and simplicity. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1518935 |
| size | 296,424 |
A powerful, composable template system for Rust
Tron is a modern template engine that brings composability and type safety to code generation. Build and compose templates with confidence, execute them with rust-script, and generate Rust code dynamically.
Add Tron to your project:
[dependencies]
tron = "0.1.0"
[features]
default = []
execute = ["tempfile", "which"] # Optional: For rust-script support
Create your first template:
use tron::{TronTemplate, TronRef};
// Create a template
let mut template = TronTemplate::new(r#"
fn @[name]@() {
println!("@[message]@");
}
"#)?;
let mut template_ref = TronRef::new(template);
// Set values
template_ref.set("name", "greet")?;
template_ref.set("message", "Hello from Tron!")?;
// Render
let code = template_ref.render()?;
Tron shines when composing templates:
// Create a module template
let mut module = TronTemplate::new(r#"
mod @[name]@ {
@[content]@
}
"#)?;
// Create a function template
let mut function = TronTemplate::new(r#"
fn @[func_name]@() {
@[body]@
}
"#)?;
// Compose them
let mut module_ref = TronRef::new(module);
let mut function_ref = TronRef::new(function);
function_ref.set("func_name", "example")?;
function_ref.set("body", "println!(\"Composed!\");")?;
module_ref.set("name", "generated")?;
module_ref.set_ref("content", function_ref)?;
// Renders:
// mod generated {
// fn example() {
// println!("Composed!");
// }
// }
Templates are the building blocks of Tron. They use a simple @[placeholder]@ syntax:
let template = TronTemplate::new("fn @[name]@() -> @[return_type]@ { @[body]@ }")?;
TronRef wraps templates with additional capabilities:
let template_ref = TronRef::new(template)
.with_dependency("serde = \"1.0\"");
Combine multiple templates with TronAssembler:
let mut assembler = TronAssembler::new();
assembler.add_template(header_ref);
assembler.add_template(body_ref);
assembler.add_template(footer_ref);
let combined = assembler.render_all()?;
Visit our documentation for:
Tron includes a VSCode extension for enhanced template editing:
.tron and .tpl filesThe extension is located in the tron_vscode/ directory. To install:
cd tron_vscode
npm install
npm run compile
code --install-extension ./tron-template-engine-1.0.0.vsix
The extension provides several configuration options:
{
"tron.validation.enabled": true,
"tron.validation.minPlaceholderLength": 2,
"tron.validation.checkTrailingWhitespace": false,
"tron.preview.autoRefresh": true,
"tron.snippets.enabled": true
}
Note: Trailing whitespace checking is disabled by default to prevent false positives. Enable it only if needed for your specific use case.
We welcome contributions! Check out our Contributing Guide to get started.
Tron is MIT licensed. See LICENSE for details.