#template #parser #templating #interpolation #mustache

varj

Ultra-lightweight string templating library. No Dependencies

4 releases (stable)

Uses new Rust 2021

1.0.2 Jan 7, 2022
1.0.0 Dec 29, 2021
0.1.0 Mar 24, 2020

#22 in Template engine

Download history 1/week @ 2021-10-06 2/week @ 2021-10-13 3/week @ 2021-10-20 2/week @ 2021-10-27 2/week @ 2021-11-03 2/week @ 2021-11-10 2/week @ 2021-11-17 4/week @ 2021-11-24 4/week @ 2021-12-01 2/week @ 2021-12-08 2/week @ 2021-12-15 1/week @ 2021-12-22 20/week @ 2021-12-29 38/week @ 2022-01-05 10/week @ 2022-01-12 11/week @ 2022-01-19

80 downloads per month

MIT/Apache

16KB
339 lines

varj Build Crates.io Documentation

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 }} with value
  • Whitespace surrounding the key is ignored: {{key}} and {{ key }} are equal.

Interact with this utility via VarjMap.

Examples

Basic usage:

let mut vars = varj::VarjMap::new();
vars.insert("key", "value");

let expected = "value";
let actual = vars.parse("{{ key }}")?;

assert_eq!(expected, actual);

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.parse(json)?;

assert_eq!(expected, actual);

VarjMap implements From<HashMap> and can be converted back to one when needed. This is useful if you want to build a VarjMap from an iterator, or itererate over one. See example.

License

Varj is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

No runtime deps