pub trait TemplateSimple: Sized {
// Required methods
fn render_once(self) -> RenderResult;
fn render_once_to(self, buf: &mut Buffer) -> Result<(), RenderError>;
}Expand description
Template which can be accessed without using self.
Required Methods§
Sourcefn render_once(self) -> RenderResult
fn render_once(self) -> RenderResult
Render the template and return the rendering result as RenderResult
This method never returns Err, unless you explicitly return RenderError
inside templates
When you use render_once method, total rendered size will be cached, and at
the next time, buffer will be pre-allocated based on the cached length.
If you don’t want this behaviour, you can use render_once_to method instead.
Sourcefn render_once_to(self, buf: &mut Buffer) -> Result<(), RenderError>
fn render_once_to(self, buf: &mut Buffer) -> Result<(), RenderError>
Render the template and append the result to buf.
This method never returns Err, unless you explicitly return RenderError
inside templates
use sailfish::TemplateSimple;
use sailfish::runtime::Buffer;
let tpl = HelloTemplate {
messages: vec!["foo".to_string()]
};
// custom pre-allocation
let mut buffer = Buffer::with_capacity(100);
tpl.render_once_to(&mut buffer).unwrap();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.