Struct HashBuilder

Source
pub struct HashBuilder<'a> { /* private fields */ }
Expand description

HashBuilder is a helper type that constructs Data types in a HashMap

Implementations§

Source§

impl<'a> HashBuilder<'a>

Source

pub fn new() -> HashBuilder<'a>

Create a new HashBuilder instance

Source

pub fn insert<K, V>(self, key: K, value: V) -> HashBuilder<'a>
where K: ToString, V: Into<Data<'a>>,

Add a Into<Data> to the HashBuilder

use rustache::HashBuilder;
use std::convert::Into;
let data = HashBuilder::new()
    .insert("game", "Hearthstone: Heroes of Warcraft");
use rustache::{HashBuilder, VecBuilder};
let data = HashBuilder::new()
    .insert("classes",
        VecBuilder::new()
            .push("Mage".to_string())
            .push("Druid".to_string())
    );
use rustache::HashBuilder;
let data = HashBuilder::new()
    .insert("hero1",
        HashBuilder::new()
            .insert("first_name", "Anduin")
            .insert("last_name", "Wrynn")
    )
    .insert("hero2",
        HashBuilder::new()
            .insert("first_name", "Jaina")
            .insert("last_name", "Proudmoore")
    );
Source

pub fn insert_lambda<K: ToString>( self, key: K, f: &'a mut dyn FnMut(String) -> String, ) -> HashBuilder<'a>

Add a Lambda that accepts a String and returns a String to the HashBuilder

use rustache::HashBuilder;
let mut f = |_| { "world".to_string() };
let data = HashBuilder::new()
    .insert_lambda("lambda", &mut f);
Source

pub fn set_partials_path(self, path: &'a str) -> HashBuilder<'a>

Set a path to partials data

Trait Implementations§

Source§

impl<'a> Debug for HashBuilder<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Render for HashBuilder<'a>

Implement the renderable trait on the HashBuilder type

Source§

fn render<W: Write>(&self, template: &str, writer: &mut W) -> Result<()>

render function on a renderable returns a reader

Auto Trait Implementations§

§

impl<'a> Freeze for HashBuilder<'a>

§

impl<'a> !RefUnwindSafe for HashBuilder<'a>

§

impl<'a> !Send for HashBuilder<'a>

§

impl<'a> !Sync for HashBuilder<'a>

§

impl<'a> Unpin for HashBuilder<'a>

§

impl<'a> !UnwindSafe for HashBuilder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.