Skip to content

Commit

Permalink
Move to the dark side to allow the parsing of filesystem templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Moreno committed Aug 10, 2020
1 parent 846e8ba commit 998acd5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ impl<'a> Template<'a> {
Cow::Borrowed(template_body) => {
TemplateParser::new(template_body, self.template_env.clone())?
}
Cow::Owned(_template_body_owned) => todo!(),
Cow::Owned(_template_body_owned) => {
// This allows the parser to have references to the template body.
// This is safe as long as `body` field is never mutated or dropped.
let unsafe_source: &'a str = unsafe{
&*(&*self.body as *const str)
};
TemplateParser::new(unsafe_source, self.template_env.clone())?
},
};
parser.parse()
}
Expand Down

0 comments on commit 998acd5

Please sign in to comment.