Expand description
A string interpolation utility to replace Mustache like placeholders with stored variables.
- Works as an extremely lightweight template library
- Does not require template compilation
- Simply replaces
{{ key }}
withvalue
- Whitespace surrounding the key is ignored:
{{key}}
and{{ key }}
are equal.
Interact with this utility via VarjMap
§Examples
Basic usage:
let mut map = varj::VarjMap::new();
map.insert("key", "value");
assert_eq!(
"value",
map.render("{{ key }}")?
);
With a json string:
let mut variables = varj::VarjMap::new();
variables.insert("name", "Christopher");
variables.insert("age", "30");
let json = r#"{
"name" = "{{ name }}",
"age" = {{ age }}
}"#;
let expected = r#"{
"name" = "Christopher",
"age" = 30
}"#;
let actual = variables.render(json)?;
assert_eq!(expected, actual);
Structs§
- Unknown key in input string
- A map of variables to replace placeholders in a string.