Generic implementation of CloneIntoBoxedContextElement.

This commit is contained in:
Tom Alexander 2020-05-10 21:07:31 -04:00
parent ba79369b5a
commit 256051220d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 11 additions and 31 deletions

View File

@ -1,7 +1,7 @@
extern crate nom; extern crate nom;
use crate::renderer::CloneIntoBoxedContextElement;
use crate::renderer::CompareContextElement; use crate::renderer::CompareContextElement;
use crate::renderer::IntoBoxedContextElement;
use parser::Filter; use parser::Filter;
use renderer::compile_template; use renderer::compile_template;
use renderer::CompiledTemplate; 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<dyn ContextElement> {
Box::new(self.clone())
}
}
impl CompareContextElement for serde_json::Value { impl CompareContextElement for serde_json::Value {
fn to_any(&self) -> &dyn Any { fn to_any(&self) -> &dyn Any {
self self

View File

@ -5,7 +5,7 @@ use std::any::Any;
use std::fmt::Debug; use std::fmt::Debug;
pub trait ContextElement: 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; fn equals(&self, other: &dyn ContextElement) -> bool;
} }
pub trait IntoBoxedContextElement { pub trait CloneIntoBoxedContextElement {
fn clone_to_box(&self) -> Box<dyn ContextElement>; fn clone_to_box(&self) -> Box<dyn ContextElement>;
} }
impl<C: 'static + ContextElement + Clone> CloneIntoBoxedContextElement for C {
fn clone_to_box(&self) -> Box<dyn ContextElement> {
Box::new(self.clone())
}
}
impl<'a, 'b> PartialEq<&'b dyn ContextElement> for &'a dyn ContextElement { impl<'a, 'b> PartialEq<&'b dyn ContextElement> for &'a dyn ContextElement {
fn eq(&self, other: &&'b dyn ContextElement) -> bool { fn eq(&self, other: &&'b dyn ContextElement) -> bool {
self.equals(*other) self.equals(*other)

View File

@ -7,9 +7,9 @@ mod parameters_context;
mod renderer; mod renderer;
mod walking; mod walking;
pub use context_element::CloneIntoBoxedContextElement;
pub use context_element::CompareContextElement; pub use context_element::CompareContextElement;
pub use context_element::ContextElement; pub use context_element::ContextElement;
pub use context_element::IntoBoxedContextElement;
pub use context_element::Loopable; pub use context_element::Loopable;
pub use context_element::Renderable; pub use context_element::Renderable;
pub use context_element::Walkable; pub use context_element::Walkable;

View File

@ -1,8 +1,8 @@
use crate::parser::KVPair; use crate::parser::KVPair;
use crate::parser::{Filter, RValue}; use crate::parser::{Filter, RValue};
use crate::renderer::context_element::CloneIntoBoxedContextElement;
use crate::renderer::context_element::CompareContextElement; use crate::renderer::context_element::CompareContextElement;
use crate::renderer::context_element::ContextElement; use crate::renderer::context_element::ContextElement;
use crate::renderer::context_element::IntoBoxedContextElement;
use crate::renderer::walking::walk_path; use crate::renderer::walking::walk_path;
use crate::renderer::Loopable; use crate::renderer::Loopable;
use crate::renderer::RenderError; use crate::renderer::RenderError;
@ -143,12 +143,6 @@ impl Walkable for String {
} }
} }
impl IntoBoxedContextElement for String {
fn clone_to_box(&self) -> Box<dyn ContextElement> {
Box::new(self.clone())
}
}
impl CompareContextElement for String { impl CompareContextElement for String {
fn to_any(&self) -> &dyn Any { fn to_any(&self) -> &dyn Any {
self self

View File

@ -245,23 +245,9 @@ impl<'a> DustRenderer<'a> {
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys), 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 { if left_side == right_side {
panic!("testing"); 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 _ => (), // TODO: Implement the rest
} }