9 unstable releases (3 breaking)
0.4.0 | Jan 5, 2020 |
---|---|
0.3.1 | Jan 4, 2020 |
0.2.0 | Jan 4, 2020 |
0.1.3 | Jan 4, 2020 |
#348 in Template engine
19KB
257 lines
replacer
Creating compilable Rust source code templates.
Example
Rust source template:
fn main() {
println!("Hello $$replace_with_string$$!");
let some_type = <replacer::rust_type!(replace_with_type; String;)>::new();
}
Rust script to parse the template:
use replacer::{rule::{StringRule, TypeRule}, TemplateBuilder};
fn main() {
let template = TemplateBuilder::new()
.rule(StringRule::new("replace_with_string", "world").unwrap())
.rule(TypeRule::new("replace_with_type", "Vec").unwrap())
.build();
println!(template.apply(include_str!(SOURCE_TEMPLATE_FROM_ABOVE)).unwrap());
}
Rust template that will be printed:
fn main() {
println!("Hello world!");
let some_type = <Vec>::new();
}
Dependencies
~2.3–3.5MB
~57K SLoC