You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
externcrate mustache;externcrate serde;use std::io;use mustache::MapBuilder;#[derive(Serde)]structPlanet{name:String,}fnmain(){// 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();println!("");// ... or you can use a builder to print "hello Venus".let data = MapBuilder::new().insert_str("name","Venus").build();
template.render_data(&mut io::stdout(),&data).unwrap();println!("");// ... you can even use closures.letmut planets = vec!("Jupiter","Mars","Earth");let data = MapBuilder::new().insert_fn("name",move |_| {
planets.pop().unwrap().into()}).build();// prints "hello Earth"
template.render_data(&mut io::stdout(),&data).unwrap();println!("");// prints "hello Mars"
template.render_data(&mut io::stdout(),&data).unwrap();println!("");// prints "hello Jupiter"
template.render_data(&mut io::stdout(),&data).unwrap();println!("");}
Testing
Simply clone and run:
cargo test
If you want to run the test cases, you'll need the spec as well.
git submodule init
git submodule update
cargo test