[][src]Crate varj

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

Interact with this utility via the parse function

Examples

Basic usage:

use std::collections::HashMap;

let mut vars = HashMap::new();
vars.insert(
    "key".to_owned(),
    "value".to_owned()
);

assert_eq!(
    "value",
    varj::parse("{{ key }}", &vars)?
);

With a json string:


let mut variables = varj::VarjMap::new();
variables.insert("name".to_owned(), "Christopher".to_owned());
variables.insert("age".to_owned(), "30".to_owned());

let json = r#"{
    "name" = "{{ name }}",
    "age" = {{ age }}
}"#;

let expected = r#"{
    "name" = "Christopher",
    "age" = 30
}"#;

let actual = varj::parse(json, &variables)?;

assert_eq!(expected, actual);

Structs

Error

Unkown key in input string

Functions

parse

Parse the input for VarjBlocks {{ key }} and replace with value

Type Definitions

VarjMap

Store keys and values of possible variables in VarjBlocks