From 256051220d3a0b8ea2b0ac1389d7fe3a043afd46 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 10 May 2020 21:07:31 -0400 Subject: [PATCH] Generic implementation of CloneIntoBoxedContextElement. --- src/bin.rs | 8 +------- src/renderer/context_element.rs | 10 ++++++++-- src/renderer/mod.rs | 2 +- src/renderer/parameters_context.rs | 8 +------- src/renderer/renderer.rs | 14 -------------- 5 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/bin.rs b/src/bin.rs index d6f9f64..3f669d4 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -1,7 +1,7 @@ extern crate nom; +use crate::renderer::CloneIntoBoxedContextElement; use crate::renderer::CompareContextElement; -use crate::renderer::IntoBoxedContextElement; use parser::Filter; use renderer::compile_template; use renderer::CompiledTemplate; @@ -141,12 +141,6 @@ impl Loopable for serde_json::Value { } } -impl IntoBoxedContextElement for serde_json::Value { - fn clone_to_box(&self) -> Box { - Box::new(self.clone()) - } -} - impl CompareContextElement for serde_json::Value { fn to_any(&self) -> &dyn Any { self diff --git a/src/renderer/context_element.rs b/src/renderer/context_element.rs index 6279a58..a9ab8bd 100644 --- a/src/renderer/context_element.rs +++ b/src/renderer/context_element.rs @@ -5,7 +5,7 @@ use std::any::Any; use std::fmt::Debug; pub trait ContextElement: - Debug + Walkable + Renderable + Loopable + IntoBoxedContextElement + CompareContextElement + Debug + Walkable + Renderable + Loopable + CloneIntoBoxedContextElement + CompareContextElement { } @@ -36,10 +36,16 @@ pub trait CompareContextElement { fn equals(&self, other: &dyn ContextElement) -> bool; } -pub trait IntoBoxedContextElement { +pub trait CloneIntoBoxedContextElement { fn clone_to_box(&self) -> Box; } +impl CloneIntoBoxedContextElement for C { + fn clone_to_box(&self) -> Box { + Box::new(self.clone()) + } +} + impl<'a, 'b> PartialEq<&'b dyn ContextElement> for &'a dyn ContextElement { fn eq(&self, other: &&'b dyn ContextElement) -> bool { self.equals(*other) diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 82a97e6..45dbdfd 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -7,9 +7,9 @@ mod parameters_context; mod renderer; mod walking; +pub use context_element::CloneIntoBoxedContextElement; pub use context_element::CompareContextElement; pub use context_element::ContextElement; -pub use context_element::IntoBoxedContextElement; pub use context_element::Loopable; pub use context_element::Renderable; pub use context_element::Walkable; diff --git a/src/renderer/parameters_context.rs b/src/renderer/parameters_context.rs index 6cdf05b..ca421bc 100644 --- a/src/renderer/parameters_context.rs +++ b/src/renderer/parameters_context.rs @@ -1,8 +1,8 @@ use crate::parser::KVPair; use crate::parser::{Filter, RValue}; +use crate::renderer::context_element::CloneIntoBoxedContextElement; use crate::renderer::context_element::CompareContextElement; use crate::renderer::context_element::ContextElement; -use crate::renderer::context_element::IntoBoxedContextElement; use crate::renderer::walking::walk_path; use crate::renderer::Loopable; use crate::renderer::RenderError; @@ -143,12 +143,6 @@ impl Walkable for String { } } -impl IntoBoxedContextElement for String { - fn clone_to_box(&self) -> Box { - Box::new(self.clone()) - } -} - impl CompareContextElement for String { fn to_any(&self) -> &dyn Any { self diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index 4b96703..a5309f3 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -245,23 +245,9 @@ impl<'a> DustRenderer<'a> { RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys), }, }; - // if left_side.unwrap().equals(right_side.unwrap()) { - // panic!("testing"); - // } - // if left_side.unwrap() == right_side.unwrap() { - // panic!("testing"); - // } if left_side == right_side { panic!("testing"); } - // let x = WalkError::CantWalk; - // let y = WalkError::CantWalk; - // if x == y { - // panic!("placeholder"); - // } - // if left_side.unwrap() == right_side.unwrap() { - // panic!("placeholder"); - // } } _ => (), // TODO: Implement the rest }