I think I have worked around the lifetime issue by keeping references to the intermediate str's.

This commit is contained in:
Tom Alexander
2023-10-22 17:43:30 -04:00
parent 58aba8efd5
commit 043cc5eda4
3 changed files with 32 additions and 26 deletions

View File

@@ -1,24 +1,27 @@
use std::collections::HashMap;
use crate::error::CustomError;
use super::renderer_integration::RendererIntegration;
use duster::renderer::DustRenderer;
use serde::Serialize;
pub(crate) struct DusterRenderer {}
pub(crate) struct DusterRenderer<'a> {
templates: HashMap<&'a str, duster::parser::Template<'a>>,
}
impl DusterRenderer {
pub(crate) fn new() -> DusterRenderer {
DusterRenderer {}
impl<'a> DusterRenderer<'a> {
pub(crate) fn new() -> DusterRenderer<'a> {
DusterRenderer {
templates: HashMap::new(),
}
}
}
impl RendererIntegration for DusterRenderer {
fn load_template<N, C>(&mut self, name: N, contents: C) -> Result<(), CustomError>
where
N: Into<String>,
C: AsRef<str>,
{
impl<'a> RendererIntegration<'a> for DusterRenderer<'a> {
fn load_template(&mut self, name: &'a str, contents: &'a str) -> Result<(), CustomError> {
let compiled_template = duster::renderer::compile_template(contents.as_ref())?;
self.templates.insert(name, compiled_template);
Ok(())
}

View File

@@ -2,11 +2,8 @@ use serde::Serialize;
use crate::error::CustomError;
pub(crate) trait RendererIntegration {
fn load_template<N, C>(&mut self, name: N, contents: C) -> Result<(), CustomError>
where
N: Into<String>,
C: AsRef<str>;
pub(crate) trait RendererIntegration<'a> {
fn load_template(&mut self, name: &'a str, contents: &'a str) -> Result<(), CustomError>;
fn render<C>(&self, context: C) -> Result<String, CustomError>
where