pub trait Template: Display + FastWritable {
const SIZE_HINT: usize;
// Required method
fn render_into_with_values<W: Write + ?Sized>(
&self,
writer: &mut W,
values: &dyn Values,
) -> Result<()>;
// Provided methods
fn render(&self) -> Result<String> { ... }
fn render_with_values(&self, values: &dyn Values) -> Result<String> { ... }
fn render_into<W: Write + ?Sized>(&self, writer: &mut W) -> Result<()> { ... }
fn write_into<W: Write + ?Sized>(&self, writer: &mut W) -> Result<()> { ... }
fn write_into_with_values<W: Write + ?Sized>(
&self,
writer: &mut W,
values: &dyn Values,
) -> Result<()> { ... }
}Expand description
Main Template trait; implementations are generally derived
If you need an object-safe template, use DynTemplate.
§Rendering performance
When rendering a askama template, you should prefer the methods
.render()(to render the content into a new string),.render_into()(to render the content into anfmt::Writeobject, e.g.String) or.write_into()(to render the content into anio::Writeobject, e.g.Vec<u8>)
over .to_string() or format!().
While .to_string() and format!() give you the same result, they generally perform much worse
than askama’s own methods, because fmt::Write uses dynamic methods calls instead of
monomorphised code. On average, expect .to_string() to be 100% to 200% slower than
.render().
Required Associated Constants§
Sourceconst SIZE_HINT: usize
const SIZE_HINT: usize
Provides a rough estimate of the expanded length of the rendered template. Larger
values result in higher memory usage but fewer reallocations. Smaller values result in the
opposite. This value only affects render. It does not take effect when calling
render_into, write_into, the fmt::Display implementation, or the blanket
ToString::to_string implementation.
Required Methods§
Provided Methods§
Sourcefn render(&self) -> Result<String>
fn render(&self) -> Result<String>
Helper method which allocates a new String and renders into it.
Sourcefn render_with_values(&self, values: &dyn Values) -> Result<String>
fn render_with_values(&self, values: &dyn Values) -> Result<String>
Helper method which allocates a new String and renders into it with provided Values.
Sourcefn render_into<W: Write + ?Sized>(&self, writer: &mut W) -> Result<()>
fn render_into<W: Write + ?Sized>(&self, writer: &mut W) -> Result<()>
Renders the template to the given writer fmt buffer.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.