replacer

Crates.ioreplacer
lib.rsreplacer
version0.4.0
sourcesrc
created_at2020-01-03 09:13:05.6172
updated_at2020-01-05 13:17:36.784119
descriptionCreating compilable Rust source code templates.
homepage
repositoryhttps://github.com/tversteeg/replacer
max_upload_size
id194743
size59,989
Thomas Versteeg (tversteeg)

documentation

https://docs.rs/replacer

README

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();
}
Commit count: 39

cargo fmt