4个稳定版本

1.0.3 2021年7月12日
1.0.2 2021年7月11日
1.0.1 2021年7月10日

#255模板引擎

42每月下载量
geoipsed中使用

MIT/Apache

6KB

microtemplate

一个快速、微观的运行时字符串插值助手库。

设计目标

  • 非常轻量级:我希望microtemplate只做一件事。如果你只需要字符串插值,没有必要包含像regex/handlebars/tinytemplate这样功能丰富/体积大的库。
    • 零额外运行时依赖:唯一使用的依赖项是用于 derive 宏,该宏在编译时处理。
  • 快速:我感兴趣的是尽可能使这个库变得最快。它现在非常快,但我相信它还不是完美的。
  • 简单.

快速入门

microtemplate添加到您的依赖项中

[dependencies]
microtemplate = "1.0.3"

使用示例(来自测试)

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 ("")
}

许可证

根据您的选择,许可协议为以下之一

贡献

除非您明确声明,否则您提交的任何贡献,按照Apache-2.0许可证的定义,都应双许可,如上所述,没有任何额外的条款或条件。

如果您有任何错误报告、改进或功能请求,请创建问题

依赖项

~1.5MB
~34K SLoC