pub trait Template: Sealed {
    fn render(&self, template: &str, options: &Options) -> Result<Serialized>;
}
Expand description

A struct that contains serde::Serialize data to insert into a template.

Create this automatically with a #[derive(Template)] attribute. All fields not marked #[raw] will be compile-time checked that they implement serde::Serialize.

Due to the nature of templating variables, tuple structs are not allowed as their fields have no names. [Unit structs] have no fields and are a valid target of this trait.

Template variables are generated as __TEMPLATE_my_field__ where the serialized value of the my_field field replaces all instances of the template variable.

Raw Values

If you have raw values you would like to inject into the template that is not serializable through JSON, such as a string of JavaScript code, then you can mark a field with #[raw] to make it embedded directly. Absolutely NO serialization occurs, the field is just turned into a string using Display. As such, fields that are marked #[raw] only require Display.

Raw values use __RAW_my_field__ as the template variable.


This trait is sealed.

Required methods

Render the serialized template data into the passed template.

Implementors