From f66b69ffc14cfecd397b32a4b2ad39e21bfaa720 Mon Sep 17 00:00:00 2001 From: KitsuneCafe <10284516+kitsunecafe@users.noreply.github.com> Date: Thu, 1 Feb 2024 14:30:59 -0500 Subject: [PATCH] make parser take a reference to context --- src/lib.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bcf2460..3537efa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,24 +1,25 @@ use roxy_core::roxy::Parse; -#[derive(Debug, Default)] -pub struct TeraParser { +#[derive(Debug)] +pub struct TeraParser<'a> { pub tera: tera::Tera, - context: tera::Context, + context: &'a tera::Context, } -impl TeraParser { - pub fn new(tera: tera::Tera, context: tera::Context) -> Self { +impl<'a> TeraParser<'a> { + pub fn new(tera: tera::Tera, context: &'a tera::Context) -> Self { Self { tera, context } } } -impl Parse for TeraParser { +impl<'a> Parse for TeraParser<'a> { fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec) -> std::io::Result<()> { // TODO: This error is a hack let err = |e: tera::Error| { println!("{e:?}"); std::io::Error::new(std::io::ErrorKind::InvalidData, e.to_string()) }; + let template = String::from_utf8_lossy(src).to_string(); self.tera