pub trait Template: Display + FastWritable {
const SIZE_HINT: usize;
// Required method
fn render_into_with_values(
&self,
writer: &mut dyn Write,
values: &dyn Values,
) -> Result<(), Error>;
// Provided methods
fn render(&self) -> Result<String, Error> { ... }
fn render_with_values(&self, values: &dyn Values) -> Result<String, Error> { ... }
fn render_into(&self, writer: &mut dyn Write) -> Result<(), Error> { ... }
fn write_into(&self, writer: &mut dyn Write) -> Result<(), Error> { ... }
fn write_into_with_values(
&self,
writer: &mut dyn Write,
values: &dyn Values,
) -> Result<(), Error> { ... }
}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§
Sourcefn render_into_with_values(
&self,
writer: &mut dyn Write,
values: &dyn Values,
) -> Result<(), Error>
fn render_into_with_values( &self, writer: &mut dyn Write, values: &dyn Values, ) -> Result<(), Error>
Renders the template to the given writer fmt buffer with provided Values.
§Errors
It internally uses the core::fmt::Write trait so it can fail and return Err for the
same reasons. For other potential errors, please take a look at the Error enum variants
documentation.
Provided Methods§
Sourcefn render(&self) -> Result<String, Error>
fn render(&self) -> Result<String, Error>
Helper method which allocates a new String and renders into it.
§Errors
It internally uses the core::fmt::Write trait so it can fail and return Err for the
same reasons. For other potential errors, please take a look at the Error enum variants
documentation.
Sourcefn render_with_values(&self, values: &dyn Values) -> Result<String, Error>
fn render_with_values(&self, values: &dyn Values) -> Result<String, Error>
Helper method which allocates a new String and renders into it with provided Values.
§Errors
It internally uses the core::fmt::Write trait so it can fail and return Err for the
same reasons. For other potential errors, please take a look at the Error enum variants
documentation.
Sourcefn render_into(&self, writer: &mut dyn Write) -> Result<(), Error>
fn render_into(&self, writer: &mut dyn Write) -> Result<(), Error>
Renders the template to the given writer fmt buffer.
§Errors
It internally uses the core::fmt::Write trait so it can fail and return Err for the
same reasons. For other potential errors, please take a look at the Error enum variants
documentation.
Sourcefn write_into(&self, writer: &mut dyn Write) -> Result<(), Error>
fn write_into(&self, writer: &mut dyn Write) -> Result<(), Error>
Renders the template to the given writer io buffer.
§Errors
It internally uses the std::io::Write trait so it can fail and return Err for the
same reasons. For other potential errors, please take a look at the Error enum variants
documentation.
Sourcefn write_into_with_values(
&self,
writer: &mut dyn Write,
values: &dyn Values,
) -> Result<(), Error>
fn write_into_with_values( &self, writer: &mut dyn Write, values: &dyn Values, ) -> Result<(), Error>
Renders the template to the given writer io buffer with provided Values.
§Errors
It internally uses the std::io::Write trait so it can fail and return Err for the
same reasons. For other potential errors, please take a look at the Error enum variants
documentation.
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.