Struct tinytemplate::TinyTemplate [−][src]
The TinyTemplate struct is the entry point for the TinyTemplate library. It contains the template and formatter registries and provides functions to render templates as well as to register templates and formatters.
Implementations
impl<'template> TinyTemplate<'template>
[src]
pub fn new() -> TinyTemplate<'template>
[src]
Create a new TinyTemplate registry. The returned registry contains no templates, and has
format_unescaped
registered as a formatter named “unescaped”.
pub fn add_template(
&mut self,
name: &'template str,
text: &'template str
) -> Result<()>
[src]
&mut self,
name: &'template str,
text: &'template str
) -> Result<()>
Parse and compile the given template, then register it under the given name.
pub fn set_default_formatter<F>(&mut self, formatter: &'template F) where
F: 'static + Fn(&Value, &mut String) -> Result<()>,
[src]
F: 'static + Fn(&Value, &mut String) -> Result<()>,
Changes the default formatter from format
to formatter
. Usefull in combination with format_unescaped
to deactivate HTML-escaping
pub fn add_formatter<F>(&mut self, name: &'template str, formatter: F) where
F: 'static + Fn(&Value, &mut String) -> Result<()>,
[src]
F: 'static + Fn(&Value, &mut String) -> Result<()>,
Register the given formatter function under the given name.
pub fn render<C>(&self, template: &str, context: &C) -> Result<String> where
C: Serialize,
[src]
C: Serialize,
Render the template with the given name using the given context object. The context
object must implement serde::Serialize
as it will be converted to serde_json::Value
.
Trait Implementations
impl<'template> Default for TinyTemplate<'template>
[src]
fn default() -> TinyTemplate<'template>
[src]
Auto Trait Implementations
impl<'template> !RefUnwindSafe for TinyTemplate<'template>
impl<'template> !Send for TinyTemplate<'template>
impl<'template> !Sync for TinyTemplate<'template>
impl<'template> Unpin for TinyTemplate<'template>
impl<'template> !UnwindSafe for TinyTemplate<'template>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,