Separating out CastToAny.

This commit is contained in:
Tom Alexander
2020-05-10 22:04:41 -04:00
parent d5e0c93205
commit 9baa669dea
3 changed files with 39 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
use crate::parser::KVPair;
use crate::parser::{Filter, RValue};
use crate::renderer::context_element::CastToAny;
use crate::renderer::context_element::CloneIntoBoxedContextElement;
use crate::renderer::context_element::CompareContextElement;
use crate::renderer::context_element::ContextElement;
@@ -111,11 +112,13 @@ impl Clone for NewParametersContext {
}
}
impl CompareContextElement for NewParametersContext {
impl CastToAny for NewParametersContext {
fn to_any(&self) -> &dyn Any {
self
}
}
impl CompareContextElement for NewParametersContext {
fn equals(&self, other: &dyn ContextElement) -> bool {
// TODO: Does this ever happen? perhaps I should have a panic here.
false
@@ -197,3 +200,15 @@ impl Walkable for String {
Err(WalkError::CantWalk)
}
}
impl CompareContextElement for String {
fn equals(&self, other: &dyn ContextElement) -> bool {
// If its a String then compare them directly, otherwise defer
// to the other type's implementation of CompareContextElement
// since the end user could add any type.
match other.to_any().downcast_ref::<Self>() {
None => other.equals(self),
Some(other_string) => self == other_string,
}
}
}