7 releases

0.3.0 Apr 1, 2024
0.2.5 Oct 22, 2023

#174 in Template engine

Download history 202/week @ 2024-07-20 219/week @ 2024-07-27 107/week @ 2024-08-03 6/week @ 2024-08-10 6/week @ 2024-08-31 7/week @ 2024-09-07 4/week @ 2024-09-21 16/week @ 2024-09-28 55/week @ 2024-10-05 28/week @ 2024-10-12 30/week @ 2024-10-19 46/week @ 2024-10-26 27/week @ 2024-11-02

168 downloads per month

MIT/Apache

48KB
867 lines

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

~2.1–7.5MB
~58K SLoC