pub struct Template<'env> { /* private fields */ }
Expand description
Represents a handle to a template.
Templates are stored in the Environment
as bytecode instructions. With the
Environment::get_template
method that is looked up and returned in form of
this handle. Such a template can be cheaply copied as it only holds references.
To render the render
method can be used.
Implementations
sourceimpl<'env> Template<'env>
impl<'env> Template<'env>
sourcepub fn render<S: Serialize>(&self, ctx: S) -> Result<String, Error>
pub fn render<S: Serialize>(&self, ctx: S) -> Result<String, Error>
Renders the template into a string.
The provided value is used as the initial context for the template. It
can be any object that implements Serialize
. You
can eiher create your own struct and derive Serialize
for it or the
context!
macro can be used to create an ad-hoc context.
let tmpl = env.get_template("hello").unwrap();
println!("{}", tmpl.render(context!(name => "John")).unwrap());
Trait Implementations
impl<'env> Copy for Template<'env>
Auto Trait Implementations
impl<'env> !RefUnwindSafe for Template<'env>
impl<'env> Send for Template<'env>
impl<'env> Sync for Template<'env>
impl<'env> Unpin for Template<'env>
impl<'env> !UnwindSafe for Template<'env>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more