markings

Crates.iomarkings
lib.rsmarkings
version0.4.0
sourcesrc
created_at2019-03-15 09:53:22.876545
updated_at2020-04-12 17:50:55.606949
descriptiona very simple string (template) replacement crate
homepage
repositoryhttps://github.com/museun/markings
max_upload_size
id121018
size21,872
(museun)

documentation

https://docs.rs/markings

README

markings

Cargo Docs.rs Github Actions

A simple string-based template 'language'

This simply allows you to replace ${key} in a string with a 'Val' that impls. std::fmt::Display

Simple usage

use markings::{Args, Template, Opts};
// template strings are simply just ${key} markers in a string
// they are replaced with a cooresponding value when .apply() is used
let input = "hello ${name}, an answer: ${greeting}.";

// parse a template with the default options
// templates are clonable, they are 'consumed' on application.
let template = Template::parse(&input, Opts::default()).unwrap();

// construct some replacement args, this is reusable
let args = Args::new()
     // with constructs a key:val pair,
     // key must be a &str,
     // value is anything that implements std::fmt::Display
    .with("name", &"test-user")
    .with("greeting", &false);    

// apply the pre-computed args to the template, consuming the template
let output = template.apply(&args).unwrap();
assert_eq!(output, "hello test-user, an answer: false.");

License: 0BSD

Commit count: 32

cargo fmt