Got rid of most of the Clone traits on the parser types since some of the parser results now contain owned values rather than just references.
This commit is contained in:
@@ -9,27 +9,16 @@ use crate::renderer::errors::CompileError;
|
||||
use crate::renderer::tree_walking::walk_path;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CompiledTemplate<'a> {
|
||||
template: Template<'a>,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DustRenderer<'a> {
|
||||
templates: HashMap<String, &'a Template<'a>>,
|
||||
}
|
||||
|
||||
pub fn compile_template<'a>(
|
||||
source: &'a str,
|
||||
name: String,
|
||||
) -> Result<CompiledTemplate<'a>, CompileError> {
|
||||
// TODO: This could use better error management
|
||||
let (_remaining, parsed_template) = template(source).expect("Failed to compile template");
|
||||
Ok(CompiledTemplate {
|
||||
template: parsed_template,
|
||||
name: name,
|
||||
})
|
||||
pub fn compile_template<'a>(source: &'a str) -> Result<Template<'a>, CompileError> {
|
||||
let (_remaining, parsed_template) = template(source).map_err(|err| CompileError {
|
||||
message: "Failed to compile template".to_owned(),
|
||||
})?;
|
||||
Ok(parsed_template)
|
||||
}
|
||||
|
||||
impl<'a> DustRenderer<'a> {
|
||||
@@ -39,9 +28,8 @@ impl<'a> DustRenderer<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_source(&mut self, template: &'a CompiledTemplate) {
|
||||
self.templates
|
||||
.insert(template.name.clone(), &template.template);
|
||||
pub fn load_source(&mut self, template: &'a Template, name: String) {
|
||||
self.templates.insert(name, template);
|
||||
}
|
||||
|
||||
/// Returns a option of a tuple of (parent, new_node_elements)
|
||||
|
||||
Reference in New Issue
Block a user