RucteConnExt

Trait RucteConnExt 

Source
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§

Source

fn render<F>(self, render_fn: F) -> Self
where F: FnOnce(&mut Vec<u8>) -> Result<()>,

Render a ructe template to this conn’s body.

Allocates a default buffer size of 1kb

Source

fn render_with_size_estimate<F>( self, render_fn: F, size_estimate: usize, ) -> Self
where F: FnOnce(&mut Vec<u8>) -> Result<()>,

Render a ructe template to this conn’s body, starting with an allocated buffer of the supplied size in bytes.

Source

fn render_html<F>(self, render_fn: F) -> Self
where F: FnOnce(&mut Vec<u8>) -> Result<()>,

Render a ructe template to this conn’s body and set a content type header of text/html.

Allocates a default buffer size of 1kb.

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.

Implementations on Foreign Types§

Source§

impl RucteConnExt for Conn

Source§

fn render<F>(self, render_fn: F) -> Self
where F: FnOnce(&mut Vec<u8>) -> Result<()>,

Source§

fn render_html<F>(self, render_fn: F) -> Self
where F: FnOnce(&mut Vec<u8>) -> Result<()>,

Source§

fn render_with_size_estimate<F>( self, render_fn: F, size_estimate: usize, ) -> Self
where F: FnOnce(&mut Vec<u8>) -> Result<()>,

Implementors§