Template

Struct Template 

Source
pub struct Template { /* private fields */ }
Expand description

A compiled moostache template.

§Examples

use moostache::Template;
use serde_json::json;
 
let template = Template::parse("hello {{name}}!").unwrap();
let data = json!({"name": "John"});
let rendered = template.render_no_partials_to_string(&data).unwrap();
assert_eq!(rendered, "hello John!");

Implementations§

Source§

impl Template

Source

pub fn parse<S: Into<Cow<'static, str>>>( source: S, ) -> Result<Template, MoostacheError>

Parse a &'static str or String into a compiled moostache template.

§Errors

Returns a MoostacheError parse error enum variant if parsing fails for whatever reason.

Source

pub fn render<K: Borrow<str> + Eq + Hash, T: TemplateLoader<K> + ?Sized, W: Write>( &self, loader: &T, value: &Value, writer: &mut W, ) -> Result<(), T::Error>

Render this template.

§Errors

If using HashMapLoader or FileLoader this function can return any enum variant of MoostacheError.

Source

pub fn render_serializable<K: Borrow<str> + Eq + Hash, T: TemplateLoader<K> + ?Sized, W: Write, S: Serialize>( &self, loader: &T, serializeable: &S, writer: &mut W, ) -> Result<(), T::Error>

Render this template given a type that impls serde::Serialize.

§Errors

If using HashMapLoader or FileLoader this function can return any enum variant of MoostacheError.

Source

pub fn render_no_partials<W: Write>( &self, value: &Value, writer: &mut W, ) -> Result<(), MoostacheError>

Render this template, assuming it has no partial tags.

§Errors

Returns a MoostacheError if the template contains a partial, or serializing data during render fails for whatever reason.

Source

pub fn render_serializable_no_partials<S: Serialize, W: Write>( &self, serializeable: &S, writer: &mut W, ) -> Result<(), MoostacheError>

Render this template using a type which impls serde::Serialize and assuming it has no partials.

§Errors

Returns a MoostacheError if the template contains a partial, or serializing data during render fails for whatever reason.

Source

pub fn render_to_string<K: Borrow<str> + Eq + Hash, T: TemplateLoader<K> + ?Sized>( &self, loader: &T, value: &Value, ) -> Result<String, T::Error>

Render this template to a String.

§Errors

If using HashMapLoader or FileLoader this function can return any enum variant of MoostacheError.

Source

pub fn render_no_partials_to_string( &self, value: &Value, ) -> Result<String, MoostacheError>

Render this template assuming it has no partial tags and return the result as a String.

§Errors

Returns a MoostacheError if the template contains a partial, or serializing data during render fails for whatever reason.

Source

pub fn render_serializable_to_string<K: Borrow<str> + Eq + Hash, T: TemplateLoader<K> + ?Sized, S: Serialize>( &self, loader: &T, serializable: &S, ) -> Result<String, T::Error>

Render this template given a type which impls serde::Serialize and return result as a String.

§Errors

If using HashMapLoader or FileLoader this function can return any enum variant of MoostacheError.

Source

pub fn render_serializable_no_partials_to_string<S: Serialize>( &self, serializable: &S, ) -> Result<String, MoostacheError>

Render this template given a type which impls serde::Serialize, assume it has no partials, and return result as a String.

§Errors

Returns a MoostacheError if the template contains a partial, or serializing data during render fails for whatever reason.

Trait Implementations§

Source§

impl Debug for Template

Source§

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

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

impl PartialEq for Template

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&'static str> for Template

Source§

type Error = MoostacheError

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

fn try_from(source: &'static str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for Template

Source§

type Error = MoostacheError

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

fn try_from(source: String) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,