#template-string #template #string #run-time

srtemplate

Template String blazing fast with dependencyless

9 releases

0.3.2 Feb 5, 2025
0.3.1 Dec 27, 2024
0.3.0 Apr 1, 2024
0.2.5 Oct 22, 2023

#101 in Template engine

Download history 48/week @ 2024-10-29 16/week @ 2024-11-05 6/week @ 2024-11-12 57/week @ 2024-11-19 61/week @ 2024-11-26 9/week @ 2024-12-03 249/week @ 2024-12-10 203/week @ 2024-12-17 170/week @ 2024-12-24 16/week @ 2024-12-31 14/week @ 2025-01-07 2/week @ 2025-01-14 54/week @ 2025-01-21 69/week @ 2025-01-28 236/week @ 2025-02-04 145/week @ 2025-02-11

504 downloads per month
Used in grow-rs

MIT/Apache

62KB
1K SLoC

srtemplate

GitHub Workflow Status (with event) Crates.io docs.rs

SrTemplate

Mr. strings template is a library that allows you to render just text templates.

  • You can see a real example here, it is a real time template renderer.
  • Documentation here
  • Wiki

Features

  • Super fast
  • Efficient
  • Renders variables of all types
  • Function system
  • Easy implementation of custom functions
  • Minimum possible dependencies
  • Feature-based implementations, use only what you need
  • Using the same variables renders multiple times

Basic example

[!NOTE] See more examples here

use srtemplate::SrTemplate;

fn main() {
    let mut ctx = SrTemplate::default();
    ctx.add_variable("var", &"World");
    ctx.add_variable("otherVar", &"Other");
    ctx.add_variable("number", &85u8);
    
    let template = "Hello {{ var }}! This is {{ otherVar }} and this is number: {{number}}";
    println!("Rendered: {}", ctx.render(template).unwrap());
}

[!NOTE] For more information about the functions implemented by default or how to use the library in depth, see the wiki

TODO's

  • I would like to change the way custom functions are implemented.
  • Macros to create custom functions
  • Better add_variable function to make more easy and performance managing Cow

Dependencies

~1.3–6.5MB
~38K SLoC