Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

Loads templates from a directory and renders them.

One engine is built at boot and shared; render takes &self so handlers can render concurrently.

Implementations§

Source§

impl Engine

Source

pub fn new(root: impl Into<PathBuf>) -> Self

Source

pub fn with_reload(self, reload: bool) -> Self

Re-read every template from disk on every render.

This is the whole reason the engine interprets an AST instead of generating Rust: with reload on, a designer edits a template, hits refresh, and sees the change — no recompile, no restart. Leave it off in production, where the parse should happen once.

Source

pub fn root(&self) -> &Path

Source

pub fn reloads(&self) -> bool

Source

pub fn exists(&self, name: &str) -> bool

Whether a view exists on disk.

Source

pub fn clear_cache(&self)

Forget every parsed template.

Source

pub fn render(&self, name: &str, context: &Context) -> Result<String>

Render the view name — "pages.home" or "pages/home" — with context as its data.

Source

pub fn render_source( &self, name: &str, source: &str, context: &Context, ) -> Result<String>

Render a template held in memory, still resolving @include and @extends through this engine’s root.

Useful for a mail body assembled in code, and for tests that have no reason to touch the disk.

Trait Implementations§

Source§

impl Default for Engine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.