Struct mustache::MapBuilder
[−]
[src]
pub struct MapBuilder { /* fields omitted */ }
MapBuilder
is a helper type that construct Data
types.
Methods
impl MapBuilder
[src]
pub fn new() -> MapBuilder
[src]
Create a MapBuilder
pub fn insert<K, T>(self, key: K, value: &T) -> Result<MapBuilder, Error> where
K: Into<String>,
T: Serialize,
[src]
K: Into<String>,
T: Serialize,
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();
pub fn insert_str<K, V>(self, key: K, value: V) -> MapBuilder where
K: Into<String>,
V: Into<String>,
[src]
K: Into<String>,
V: Into<String>,
Add a String
to the MapBuilder
.
use mustache::MapBuilder; let data = MapBuilder::new() .insert_str("name", "Jane Austen") .build();
pub fn insert_bool<K>(self, key: K, value: bool) -> MapBuilder where
K: Into<String>,
[src]
K: Into<String>,
Add a bool
to the MapBuilder
.
use mustache::MapBuilder; let data = MapBuilder::new() .insert_bool("show", true) .build();
pub fn insert_vec<K, F>(self, key: K, f: F) -> MapBuilder where
K: Into<String>,
F: FnMut(VecBuilder) -> VecBuilder,
[src]
K: Into<String>,
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();
pub fn insert_map<K, F>(self, key: K, f: F) -> MapBuilder where
K: Into<String>,
F: FnMut(MapBuilder) -> MapBuilder,
[src]
K: Into<String>,
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();
pub 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();
pub 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