Crates.io | replacer |
lib.rs | replacer |
version | 0.4.0 |
source | src |
created_at | 2020-01-03 09:13:05.6172 |
updated_at | 2020-01-05 13:17:36.784119 |
description | Creating compilable Rust source code templates. |
homepage | |
repository | https://github.com/tversteeg/replacer |
max_upload_size | |
id | 194743 |
size | 59,989 |
Creating compilable Rust source code templates.
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();
}