tentatively seems to be working.
This commit is contained in:
parent
c96b2257d7
commit
8fd2a9cf39
15
src/bin.rs
15
src/bin.rs
@ -1,5 +1,6 @@
|
|||||||
extern crate nom;
|
extern crate nom;
|
||||||
|
|
||||||
|
use crate::renderer::CompareContextElement;
|
||||||
use crate::renderer::IntoBoxedContextElement;
|
use crate::renderer::IntoBoxedContextElement;
|
||||||
use parser::Filter;
|
use parser::Filter;
|
||||||
use renderer::compile_template;
|
use renderer::compile_template;
|
||||||
@ -11,6 +12,7 @@ use renderer::RenderError;
|
|||||||
use renderer::Renderable;
|
use renderer::Renderable;
|
||||||
use renderer::WalkError;
|
use renderer::WalkError;
|
||||||
use renderer::Walkable;
|
use renderer::Walkable;
|
||||||
|
use std::any::Any;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{self, Read};
|
use std::io::{self, Read};
|
||||||
@ -144,3 +146,16 @@ impl IntoBoxedContextElement for serde_json::Value {
|
|||||||
Box::new(self.clone())
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -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
|
Debug + Walkable + Renderable + Loopable + IntoBoxedContextElement + CompareContextElement
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +32,8 @@ pub trait Loopable {
|
|||||||
|
|
||||||
pub trait CompareContextElement {
|
pub trait CompareContextElement {
|
||||||
fn to_any(&self) -> &dyn Any;
|
fn to_any(&self) -> &dyn Any;
|
||||||
|
|
||||||
|
fn equals(&self, other: &dyn ContextElement) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IntoBoxedContextElement {
|
pub trait IntoBoxedContextElement {
|
||||||
|
@ -7,6 +7,7 @@ mod parameters_context;
|
|||||||
mod renderer;
|
mod renderer;
|
||||||
mod walking;
|
mod walking;
|
||||||
|
|
||||||
|
pub use context_element::CompareContextElement;
|
||||||
pub use context_element::ContextElement;
|
pub use context_element::ContextElement;
|
||||||
pub use context_element::IntoBoxedContextElement;
|
pub use context_element::IntoBoxedContextElement;
|
||||||
pub use context_element::Loopable;
|
pub use context_element::Loopable;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::parser::KVPair;
|
use crate::parser::KVPair;
|
||||||
use crate::parser::{Filter, RValue};
|
use crate::parser::{Filter, RValue};
|
||||||
|
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::context_element::IntoBoxedContextElement;
|
||||||
use crate::renderer::walking::walk_path;
|
use crate::renderer::walking::walk_path;
|
||||||
@ -8,6 +9,7 @@ use crate::renderer::RenderError;
|
|||||||
use crate::renderer::Renderable;
|
use crate::renderer::Renderable;
|
||||||
use crate::renderer::WalkError;
|
use crate::renderer::WalkError;
|
||||||
use crate::renderer::Walkable;
|
use crate::renderer::Walkable;
|
||||||
|
use std::any::Any;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// Copy the data from an RValue to an Owned struct
|
/// Copy the data from an RValue to an Owned struct
|
||||||
@ -146,3 +148,16 @@ impl IntoBoxedContextElement for String {
|
|||||||
Box::new(self.clone())
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -245,6 +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");
|
||||||
|
}
|
||||||
// let x = WalkError::CantWalk;
|
// let x = WalkError::CantWalk;
|
||||||
// let y = WalkError::CantWalk;
|
// let y = WalkError::CantWalk;
|
||||||
// if x == y {
|
// if x == y {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user