pub trait RucteConnExt {
// Required methods
fn render<F>(self, render_fn: F) -> Self
where F: FnOnce(&mut Vec<u8>) -> Result<()>;
fn render_with_size_estimate<F>(
self,
render_fn: F,
size_estimate: usize,
) -> Self
where F: FnOnce(&mut Vec<u8>) -> Result<()>;
fn render_html<F>(self, render_fn: F) -> Self
where F: FnOnce(&mut Vec<u8>) -> Result<()>;
}Expand description
Renders a template and sets content-type as “text/html; charset=utf-8” or returns the conn with a 500 status.
ⓘ
use trillium::Conn;
use trillium_ructe::RucteConnExt;
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
fn main() {
trillium_smol::run(|conn: Conn| async move {
// helloworld.rs.html contents:
// @(text: &str)
// <h1>@text</h1>
conn.render_html(|o| templates::helloworld(o, "hello world"))
});
}
Required Methods§
Sourcefn render<F>(self, render_fn: F) -> Self
fn render<F>(self, render_fn: F) -> Self
Render a ructe template to this conn’s body.
Allocates a default buffer size of 1kb
Sourcefn render_with_size_estimate<F>(
self,
render_fn: F,
size_estimate: usize,
) -> Self
fn render_with_size_estimate<F>( self, render_fn: F, size_estimate: usize, ) -> Self
Render a ructe template to this conn’s body, starting with an allocated buffer of the supplied size in bytes.
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.