pub trait TemplateExt: Template {
// Provided methods
fn render_dynamic_self(
&self,
data: &<Self as Template>::Argument,
) -> Result<Vec<u8>, DynamicError>
where Self: Sized,
<Self as Template>::Argument: Serialize + for<'de> Deserialize<'de> + 'static { ... }
fn render_dynamic(
&self,
path: &Path,
data: &<Self as Template>::Argument,
) -> Result<Vec<u8>, DynamicError>
where Self: Sized,
<Self as Template>::Argument: Serialize + for<'de> Deserialize<'de> + 'static { ... }
fn render_static(
&self,
data: &<Self as Template>::Argument,
) -> Result<Vec<u8>>
where Self: Sized,
<Self as Template>::Argument: Serialize + for<'de> Deserialize<'de> + 'static { ... }
}Expand description
Convinience methods for Template
Provided Methods§
Sourcefn render_dynamic_self(
&self,
data: &<Self as Template>::Argument,
) -> Result<Vec<u8>, DynamicError>
fn render_dynamic_self( &self, data: &<Self as Template>::Argument, ) -> Result<Vec<u8>, DynamicError>
Call current binary file to handle the template
Make sure to put handle_dynamic at the very beginning of your
binary if you want to use it.
See render_dynamic for more info.
This function will behave like render_static if
STPL_PROD environment variable is enabled.
Sourcefn render_dynamic(
&self,
path: &Path,
data: &<Self as Template>::Argument,
) -> Result<Vec<u8>, DynamicError>
fn render_dynamic( &self, path: &Path, data: &<Self as Template>::Argument, ) -> Result<Vec<u8>, DynamicError>
Call a template dynamically (with ability to update at runtime)
Make sure to put handle_dynamic at the very beginning of the code
of program under path.
data type must be the same as template expects.
The template will evaluate in another process, so you can’t rely on value of globals, and such, but otherwise it’s transparent.
It works by serializing data and passing it to a child process.
The child process is the current binary, with environment variable
pointing to the right template. handle_dynamic will detect
being a dynamic-template-child, deserialize data, render
the template and write the output to stdout. This will
be used as a transparent Template.
This function will behave like render_static if
STPL_PROD environment variable is enabled.