Crates.io | varj |
lib.rs | varj |
version | 1.2.0 |
source | src |
created_at | 2020-03-24 13:59:15.261224 |
updated_at | 2024-07-14 08:35:56.314283 |
description | Ultra-lightweight string templating library. No Dependencies |
homepage | |
repository | https://github.com/sonro/varj |
max_upload_size | |
id | 222298 |
size | 39,414 |
A string interpolation utility to replace Mustache like placeholders with stored variables.
{{ key }}
with value
{{key}}
and {{ key }}
are equal.Interact with this utility via
VarjMap
.
Basic usage:
let mut map = varj::VarjMap::new();
map.insert("key", "value");
let expected = "value";
let actual = map.render("{{ 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.render(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 iterate over one. See example.
The minimum supported Rust version is currently 1.71.1.
varj supports the latest 8 stable releases of Rust - approximately 1 year. Increasing MSRV is not considered a semver-breaking change.
Thank you very much for considering to contribute to this project!
We welcome any form of contribution:
Note: Before you take the time to open a pull request, please open an issue first.
See CONTRIBUTING.md for details.
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.