Skip to content
Experimental Mustache template engine implementation in pure Rust.
Branch: master
Clone or download
Latest commit ba0c44e Mar 20, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
ramhorns-derive Added CommonMark support via #[md] attribute (#8) Mar 20, 2019
ramhorns Release v0.5.0 Mar 20, 2019
tests Added CommonMark support via #[md] attribute (#8) Mar 20, 2019
.gitignore Initial commit Feb 25, 2019
LICENSE Update README Mar 20, 2019
ramhorns.svg Logo and stuff Feb 27, 2019

Ramhorns logo


Travis shield version shield license shield

Experimental Mustache template engine implementation in pure Rust.

Ramhorns loads and processes templates at runtime. It comes with a derive macro which allows for templates to be rendered from native Rust data structures without doing temporary allocations, intermediate HashMaps or what have you.

With a touch of magic 🎩, the power of friendship 🥂, and a sparkle of FNV hashing , render times easily compete with static template engines like Askama.

What else do you want, a sticker?


ramhorns = "0.5"


use ramhorns::{Template, Content};

struct Post<'a> {
    title: &'a str,
    teaser: &'a str,

struct Blog<'a> {
    title: String,        // Strings are cool
    posts: Vec<Post<'a>>, // &'a [Post<'a>] would work too

// Standard Mustache action here
let source = "<h1>{{title}}</h1>\
              {{^posts}}<p>No posts yet :(</p>{{/posts}}";

let tpl = Template::new(source).unwrap();

let rendered = tpl.render(&Blog {
    title: "My Awesome Blog!".to_string(),
    posts: vec![
        Post {
            title: "How I tried Ramhorns and found love 💖",
            teaser: "This can happen to you too",
        Post {
            title: "Rust is kinda awesome",
            teaser: "Yes, even the borrow checker! 🦀",

assert_eq!(rendered, "<h1>My Awesome Blog!</h1>\
                          <h2>How I tried Ramhorns and found love 💖</h2>\
                          <p>This can happen to you too</p>\
                          <h2>Rust is kinda awesome</h2>\
                          <p>Yes, even the borrow checker! 🦀</p>\

Features so far

  • Rendering common types, such as &str, String, bools, and numbers into {{variables}}.
  • Unescaped printing with {{{tripple-brace}}} or {{&ampersant}}.
  • Rendering sections {{#foo}} ... {{/foo}}.
  • Rendering inverse sections {{^foo}} ... {{/foo}}.
  • Zero-copy CommonMark rendering from fields marked with #[md].


running 5 tests
test a_simple_ramhorns   ... bench:          64 ns/iter (+/- 4)
test b_simple_wearte     ... bench:          72 ns/iter (+/- 24)
test c_simple_askama     ... bench:         181 ns/iter (+/- 9)
test d_simple_mustache   ... bench:         736 ns/iter (+/- 133)
test e_simple_handlebars ... bench:       2,889 ns/iter (+/- 118)

Worth noting here is that both Askama and wearte (a fork of a fork of Askama) are processing templates at compile time and generate static rust code for rendering. This is great for performance, but it also means you can't swap out templates without recompiling your Rust binaries. In some cases, like for a static site generator, this is unfortunately a deal breaker.

The Mustache crate is the closest thing to Ramhorns in design and feature set.


Ramhorns is free software, and is released under the terms of the GNU General Public License version 3. See LICENSE.

You can’t perform that action at this time.