Invoking the compile function.

I am going to have to address the lifetime issue of "compiled" duster templates borrowing the input str.
This commit is contained in:
Tom Alexander 2023-10-22 17:37:27 -04:00
parent ce0819e85b
commit 58aba8efd5
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 15 additions and 5 deletions

View File

@ -12,6 +12,7 @@ pub(crate) enum CustomError {
Serde(serde_json::Error),
Utf8(Utf8Error),
FromUtf8(FromUtf8Error),
DusterCompile(duster::renderer::CompileError),
}
impl From<std::io::Error> for CustomError {
@ -67,3 +68,9 @@ impl From<FromUtf8Error> for CustomError {
CustomError::FromUtf8(value)
}
}
impl From<duster::renderer::CompileError> for CustomError {
fn from(value: duster::renderer::CompileError) -> Self {
CustomError::DusterCompile(value)
}
}

View File

@ -1,3 +1,5 @@
use crate::error::CustomError;
use super::renderer_integration::RendererIntegration;
use duster::renderer::DustRenderer;
use serde::Serialize;
@ -11,15 +13,16 @@ impl DusterRenderer {
}
impl RendererIntegration for DusterRenderer {
fn load_template<N, C>(&mut self, name: N, contents: C) -> Result<(), crate::error::CustomError>
fn load_template<N, C>(&mut self, name: N, contents: C) -> Result<(), CustomError>
where
N: Into<String>,
C: Into<String>,
C: AsRef<str>,
{
let compiled_template = duster::renderer::compile_template(contents.as_ref())?;
Ok(())
}
fn render<C>(&self, context: C) -> Result<String, crate::error::CustomError>
fn render<C>(&self, context: C) -> Result<String, CustomError>
where
C: Serialize,
{

View File

@ -6,9 +6,9 @@ pub(crate) trait RendererIntegration {
fn load_template<N, C>(&mut self, name: N, contents: C) -> Result<(), CustomError>
where
N: Into<String>,
C: Into<String>;
C: AsRef<str>;
fn render<C>(&self, context: C) -> Result<String, crate::error::CustomError>
fn render<C>(&self, context: C) -> Result<String, CustomError>
where
C: Serialize;
}