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

Object Safety§

This trait is not object safe.

Implementors§