Skip to content
mustache template library for rust
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.
examples doc(examples): add compile_path example Mar 13, 2018
spec @ 9b1bc7a Import the mustache specs Feb 26, 2012
src Test readme using the doc(include) feature on nightly only for now Feb 12, 2018
.gitignore Modernize a little bit! Aug 27, 2014
.gitmodules Import the mustache specs Feb 26, 2012
.travis.yml Test readme using the doc(include) feature on nightly only for now Feb 12, 2018
Cargo.toml feat(version): 0.9.0 Feb 12, 2018
LICENSE fix(Readme): fix link to docs Feb 13, 2018
rustfmt.toml style(*): rustfmt Jul 2, 2016

Mustache Ohloh statistics Build Status

Inspired by ctemplate and et, Mustache is a framework-agnostic way to render logic-free views.

As ctemplates says, "It emphasizes separating logic from presentation: it is impossible to embed application logic in this template language."

rust-mustache is a rust implementation of Mustache.


The different Mustache tags are documented at mustache(5).

Documentation for this library is here.


Install it through Cargo!

mustache = "*"

Basic example

extern crate serde_derive;
extern crate mustache;

use std::io;
use mustache::MapBuilder;

struct Planet {
    name: String,

fn main() {
    // First the string needs to be compiled.
    let template = mustache::compile_str("hello {{name}}").unwrap();

    // You can either use an encodable type to print "hello Mercury".
    let planet = Planet { name: "Mercury".into() };
    template.render(&mut io::stdout(), &planet).unwrap();

    // ... or you can use a builder to print "hello Venus".
    let data = MapBuilder::new()
        .insert_str("name", "Venus")

    template.render_data(&mut io::stdout(), &data).unwrap();

    // ... you can even use closures.
    let mut planets = vec!("Jupiter", "Mars", "Earth");

    let data = MapBuilder::new()
        .insert_fn("name", move |_| {

    // prints "hello Earth"
    template.render_data(&mut io::stdout(), &data).unwrap();

    // prints "hello Mars"
    template.render_data(&mut io::stdout(), &data).unwrap();

    // prints "hello Jupiter"
    template.render_data(&mut io::stdout(), &data).unwrap();


Simply clone and run:

# If you want to run the test cases, you'll need the spec as well.
git submodule init
git submodule update

cargo test

# If you want to test the readme example, we're currently using the unstable feature to do so.
cargo +nightly test --features unstable


If cutting a new release, please follow something along the lines of the below:

# Assuming master is the current release commit, ideally it will be a commit
# announcing the release and the only change would be the version number.

# Ensure everything looks good
cargo publish --dry-run

# Actually publish
cargo publish

# Tag the release, prefix it with 'v' for easy tag searching, i.e. git tag --list 'v*'
git tag vX.Y.Z

git push --tags origin master



You can’t perform that action at this time.