Struct mustache::builder::MapBuilder
[−]
[src]
pub struct MapBuilder { /* fields omitted */ }
MapBuilder
is a helper type that construct Data
types.
Methods
impl MapBuilder
[src]
fn new() -> MapBuilder
[src]
Create a MapBuilder
fn insert<K: ToString, T: Encodable>(
self,
key: K,
value: &T
) -> Result<MapBuilder, Error>
[src]
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")).expect("Failed to encode name") .insert("age", &41usize).expect("Failed to encode age") .build();
fn insert_str<K: ToString, V: ToString>(self, key: K, value: V) -> MapBuilder
[src]
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
[src]
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,
[src]
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,
[src]
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,
[src]
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
[src]
Return the built Data
.
Trait Implementations
impl Default for MapBuilder
[src]
fn default() -> MapBuilder
[src]
Returns the "default value" for a type. Read more