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§
Sourcetype Error: IntoResponse
type Error: IntoResponse
Error type returned if the engine is unable to process the data
Required Methods§
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>>
impl TemplateEngine for Engine<Handlebars<'static>>
type Error = HandlebarsError
Source§impl TemplateEngine for Engine<AutoReloader>
Available on crate feature minijinja-autoreload only.
impl TemplateEngine for Engine<AutoReloader>
Available on crate feature
minijinja-autoreload only.type Error = MinijinjaError
Source§impl TemplateEngine for Engine<Environment<'static>>
Available on crate feature minijinja only.
impl TemplateEngine for Engine<Environment<'static>>
Available on crate feature
minijinja only.