tentatively seems to be working.

This commit is contained in:
Tom Alexander 2020-05-10 19:16:55 -04:00
parent c96b2257d7
commit 8fd2a9cf39
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 37 additions and 1 deletions

View File

@ -1,5 +1,6 @@
extern crate nom;
use crate::renderer::CompareContextElement;
use crate::renderer::IntoBoxedContextElement;
use parser::Filter;
use renderer::compile_template;
@ -11,6 +12,7 @@ use renderer::RenderError;
use renderer::Renderable;
use renderer::WalkError;
use renderer::Walkable;
use std::any::Any;
use std::env;
use std::fs;
use std::io::{self, Read};
@ -144,3 +146,16 @@ impl IntoBoxedContextElement for serde_json::Value {
Box::new(self.clone())
}
}
impl CompareContextElement for serde_json::Value {
fn to_any(&self) -> &dyn Any {
self
}
fn equals(&self, other: &dyn ContextElement) -> bool {
other
.to_any()
.downcast_ref::<Self>()
.map_or(false, |a| self == a)
}
}

View File

@ -5,7 +5,7 @@ use std::any::Any;
use std::fmt::Debug;
pub trait ContextElement:
Debug + Walkable + Renderable + Loopable + IntoBoxedContextElement
Debug + Walkable + Renderable + Loopable + IntoBoxedContextElement + CompareContextElement
{
}
@ -32,6 +32,8 @@ pub trait Loopable {
pub trait CompareContextElement {
fn to_any(&self) -> &dyn Any;
fn equals(&self, other: &dyn ContextElement) -> bool;
}
pub trait IntoBoxedContextElement {

View File

@ -7,6 +7,7 @@ mod parameters_context;
mod renderer;
mod walking;
pub use context_element::CompareContextElement;
pub use context_element::ContextElement;
pub use context_element::IntoBoxedContextElement;
pub use context_element::Loopable;

View File

@ -1,5 +1,6 @@
use crate::parser::KVPair;
use crate::parser::{Filter, RValue};
use crate::renderer::context_element::CompareContextElement;
use crate::renderer::context_element::ContextElement;
use crate::renderer::context_element::IntoBoxedContextElement;
use crate::renderer::walking::walk_path;
@ -8,6 +9,7 @@ use crate::renderer::RenderError;
use crate::renderer::Renderable;
use crate::renderer::WalkError;
use crate::renderer::Walkable;
use std::any::Any;
use std::collections::HashMap;
/// Copy the data from an RValue to an Owned struct
@ -146,3 +148,16 @@ impl IntoBoxedContextElement for String {
Box::new(self.clone())
}
}
impl CompareContextElement for String {
fn to_any(&self) -> &dyn Any {
self
}
fn equals(&self, other: &dyn ContextElement) -> bool {
other
.to_any()
.downcast_ref::<Self>()
.map_or(false, |a| self == a)
}
}

View File

@ -245,6 +245,9 @@ impl<'a> DustRenderer<'a> {
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys),
},
};
if left_side.unwrap().equals(right_side.unwrap()) {
panic!("testing");
}
// let x = WalkError::CantWalk;
// let y = WalkError::CantWalk;
// if x == y {