#template #source #rust

replacer

Creating compilable Rust source code templates

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

#308 in Template engine

27 downloads per month

GPL-3.0 license

19KB
257 lines

replacer

Creating compilable Rust source code templates.

Build Status Version Rust Documentation License

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.2–3MB
~55K SLoC