Skip to main content

TemplateEngine

Trait TemplateEngine 

Source
pub trait TemplateEngine {
    type Error: IntoResponse;

    // Required method
    fn render<S: Serialize>(
        &self,
        key: &str,
        data: S,
    ) -> Result<String, Self::Error>;
}
Expand description

An abstraction over different templating engines

§Implementing custom engines


#[derive(Debug)]
pub struct CustomEngine;

impl TemplateEngine for CustomEngine {
    type Error = Infallible;   
    fn render<S: Serialize>(&self, key: &str, data: S) -> Result<String, Self::Error> {
        /* Render your template and return the result */
        let result = "Hello world".into();
        Ok(result)    
    }
}

See the full working example custom_engine.rs

Required Associated Types§

Source

type Error: IntoResponse

Error type returned if the engine is unable to process the data

Required Methods§

Source

fn render<S: Serialize>( &self, key: &str, data: S, ) -> Result<String, Self::Error>

Renders the template defined by the given key using the Serializable data

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl TemplateEngine for Engine<Handlebars<'static>>

Source§

impl TemplateEngine for Engine<AutoReloader>

Available on crate feature minijinja-autoreload only.
Source§

impl TemplateEngine for Engine<Environment<'static>>

Available on crate feature minijinja only.
Source§

impl TemplateEngine for Engine<Tera>