I think I have worked around the lifetime issue by keeping references to the intermediate str's.
This commit is contained in:
@@ -38,12 +38,20 @@ impl SiteRenderer {
|
||||
return Err("Expect exactly 1 main.dust template file.".into());
|
||||
}
|
||||
|
||||
for entry in main_template {
|
||||
load_template_from_include_dir(&mut renderer_integration, entry)?;
|
||||
}
|
||||
let decoded_templates = {
|
||||
let mut decoded_templates =
|
||||
Vec::with_capacity(main_template.len() + other_templates.len());
|
||||
for entry in main_template {
|
||||
decoded_templates.push(build_name_contents_pairs(entry)?);
|
||||
}
|
||||
for entry in other_templates {
|
||||
decoded_templates.push(build_name_contents_pairs(entry)?);
|
||||
}
|
||||
decoded_templates
|
||||
};
|
||||
|
||||
for entry in other_templates {
|
||||
load_template_from_include_dir(&mut renderer_integration, entry)?;
|
||||
for (name, contents) in decoded_templates {
|
||||
renderer_integration.load_template(name, contents)?;
|
||||
}
|
||||
|
||||
for blog_post in &self.blog_posts {
|
||||
@@ -55,10 +63,9 @@ impl SiteRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
fn load_template_from_include_dir<RI: RendererIntegration>(
|
||||
renderer_integration: &mut RI,
|
||||
entry: &include_dir::File<'_>,
|
||||
) -> Result<(), CustomError> {
|
||||
fn build_name_contents_pairs<'a>(
|
||||
entry: &'a include_dir::File<'_>,
|
||||
) -> Result<(&'a str, &'a str), CustomError> {
|
||||
let path = entry.path();
|
||||
let name = path
|
||||
.file_stem()
|
||||
@@ -66,6 +73,5 @@ fn load_template_from_include_dir<RI: RendererIntegration>(
|
||||
.to_str()
|
||||
.ok_or("All template filenames should be valid utf-8.")?;
|
||||
let contents = std::str::from_utf8(entry.contents())?;
|
||||
renderer_integration.load_template(name, contents)?;
|
||||
Ok(())
|
||||
Ok((name, contents))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user