#template

string_template

Very simple string template for Rust

1 unstable release

0.1.0 Nov 1, 2018

#72 in Template engine

Download history 12/week @ 2018-11-02

4 downloads per month

MIT/Apache

5KB
68 lines

string_template

Very simple string template for Rust

Usage

Add this to your Cargo.toml:

[dependencies]
string_template = "0.1.0"

and this to your crate root:

extern crate string_template;

Here's a simple example:

extern crate string_template;

use string_template::Template;
use std::collections::HashMap;

fn main() {
    let template = Template::new("Hi, my name is {{name}} and I'm a {{lang}} developer.");

    let mut args = HashMap::new();
    args.insert("name", "Michael");
    args.insert("lang", "Rust");
    let s = template.render(&args);

    assert_eq!(s, "Hi, my name is Michael and I'm a Rust developer.");

    let mut args1 = HashMap::new();
    args1.insert("name", "Vader");
    args1.insert("lang", "Dart");
    let s2 = template.render(&args1);

    assert_eq!(s2, "Hi, my name is Vader and I'm a Dart developer.");
}

Dependencies

~2MB
~35K SLoC