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
impl Template
Sourcepub fn parse<S: Into<Cow<'static, str>>>(
source: S,
) -> Result<Template, MoostacheError>
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.
Sourcepub fn render<K: Borrow<str> + Eq + Hash, T: TemplateLoader<K> + ?Sized, W: Write>(
&self,
loader: &T,
value: &Value,
writer: &mut W,
) -> Result<(), T::Error>
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.
Sourcepub 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>
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.
Sourcepub fn render_no_partials<W: Write>(
&self,
value: &Value,
writer: &mut W,
) -> Result<(), MoostacheError>
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.
Sourcepub fn render_serializable_no_partials<S: Serialize, W: Write>(
&self,
serializeable: &S,
writer: &mut W,
) -> Result<(), MoostacheError>
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.
Sourcepub fn render_to_string<K: Borrow<str> + Eq + Hash, T: TemplateLoader<K> + ?Sized>(
&self,
loader: &T,
value: &Value,
) -> Result<String, T::Error>
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.
Sourcepub fn render_no_partials_to_string(
&self,
value: &Value,
) -> Result<String, MoostacheError>
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.
Sourcepub 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>
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.
Sourcepub fn render_serializable_no_partials_to_string<S: Serialize>(
&self,
serializable: &S,
) -> Result<String, MoostacheError>
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.