Struct mustache::builder::MapBuilder
[−]
[src]
pub struct MapBuilder {
// some fields omitted
}MapBuilder is a helper type that construct Data types.
Methods
impl MapBuilder
fn new() -> MapBuilder
Create a MapBuilder
fn insert<K: ToString, T: Encodable>(self, key: K, value: &T) -> Result<MapBuilder, Error>
Add an Encodable to the MapBuilder.
use mustache::MapBuilder; let data = MapBuilder::new() .insert("name", &("Jane Austen")).ok().unwrap() .insert("age", &41usize).ok().unwrap() .build();
fn insert_str<K: ToString, V: ToString>(self, key: K, value: V) -> MapBuilder
Add a String to the MapBuilder.
use mustache::MapBuilder; let data = MapBuilder::new() .insert_str("name", "Jane Austen") .build();
fn insert_bool<K: ToString>(self, key: K, value: bool) -> MapBuilder
Add a bool to the MapBuilder.
use mustache::MapBuilder; let data = MapBuilder::new() .insert_bool("show", true) .build();
fn insert_vec<K: ToString, F>(self, key: K, f: F) -> MapBuilder where F: FnMut(VecBuilder) -> VecBuilder
Add a Vec to the MapBuilder.
use mustache::MapBuilder; let data = MapBuilder::new() .insert_vec("authors", |builder| { builder .push_str("Jane Austen") .push_str("Lewis Carroll") }) .build();
fn insert_map<K: ToString, F>(self, key: K, f: F) -> MapBuilder where F: FnMut(MapBuilder) -> MapBuilder
Add a Map to the MapBuilder.
use mustache::MapBuilder; let data = MapBuilder::new() .insert_map("person1", |builder| { builder .insert_str("first_name", "Jane") .insert_str("last_name", "Austen") }) .insert_map("person2", |builder| { builder .insert_str("first_name", "Lewis") .insert_str("last_name", "Carroll") }) .build();
fn insert_fn<K: ToString, F>(self, key: K, f: F) -> MapBuilder where F: FnMut(String) -> String + Send + 'static
Add a function to the MapBuilder.
use mustache::MapBuilder; let mut count = 0; let data = MapBuilder::new() .insert_fn("increment", move |_| { count += 1usize; count.to_string() }) .build();
fn build(self) -> Data
Return the built Data.