lazy-template

Crates.iolazy-template
lib.rslazy-template
version0.0.0
sourcesrc
created_at2024-10-06 08:11:01.543074
updated_at2024-10-06 08:11:01.543074
descriptionString template library that send queries to function responder and interpolate the responses
homepage
repositoryhttps://github.com/KSXGitHub/lazy-template.git
max_upload_size
id1398883
size40,229
Khải (KSXGitHub)

documentation

https://docs.rs/lazy-template

README

lazy-template

Description

This is a string template crate. Instead of requiring a complete set of inputs (such as via a struct, a HashMap, or a JSON object) to be available, the templates from this crate would send queries (which would usually be the names of the variables) to a function (called "responder") to get the value of each query.

Documentation

Go to docs.rs.

Basic Usage

This is the most basic usage. There are more in the documentation.

let system = lazy_template::simple_curly_braces();
let template = system.lazy_parse("{name} is a {age} years old {gender}");
let output = template
    .to_string(|query| match query {
        "name" => Ok("Alice"),
        "age" => Ok("20"),
        "gender" => Ok("girl"),
        _ => Err(format!("Can't answer {query}")),
    })
    .unwrap();
assert_eq!(output, "Alice is a 20 years old girl");

License

MIT © Hoàng Văn Khải

Commit count: 84

cargo fmt