Trait sailfish::TemplateOnce
source · pub trait TemplateOnce: Sized + Sealed {
// Required methods
fn render_once(self) -> RenderResult;
fn render_once_to(self, buf: &mut Buffer) -> Result<(), RenderError>;
}
Expand description
Template that can be rendered with consuming itself.
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::TemplateOnce;
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();
Object Safety§
This trait is not object safe.