Crates.io | microtemplate |
lib.rs | microtemplate |
version | 1.0.3 |
source | src |
created_at | 2021-07-10 22:06:11.967126 |
updated_at | 2021-07-12 19:42:54.810643 |
description | Fast, microscopic helper crate for runtime string interpolation. |
homepage | |
repository | https://github.com/Legend-of-iPhoenix/microtemplate |
max_upload_size | |
id | 421220 |
size | 9,399 |
A fast, microscopic helper crate for runtime string interpolation.
microtemplate
to do exactly one thing. There's no reason to include more feature-rich/large libraries like regex
/handlebars
/tinytemplate
if all you need is string interpolation.Add microtemplate
to your dependencies:
[dependencies]
microtemplate = "1.0.3"
Usage example (from the tests):
use microtemplate::{Substitutions, render};
// This derive allows microtemplate to use the struct as substitutions.
#[derive(Substitutions)]
struct Movie<'a> {
name: &'a str, // automatically replaces "{name}" in a template
description: &'a str,
}
fn main() {
let the_birds = Movie {
name: "The Birds",
description: "a swarm of birds that suddenly and violently attack the residents of a California coastal town",
};
// the template string here can be generated whenever- in this example it
// is known at compile time but that does not matter.
let rendered = render("{name} is a movie about {description}.", the_birds);
// The Birds is a movie about a swarm of birds that suddenly and violently
// attack the residents of a California coastal town.
println!("{}", rendered);
// note that if a substitution is indicated in the template string but it is
// not found in the struct passed, it is replaced with an empty string ("")
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
If you have any bug reports, improvements, or feature requests, please make an issue