Generic implementation of CompareContextElement.

This commit is contained in:
Tom Alexander 2020-05-10 21:10:48 -04:00
parent 256051220d
commit 32abe41e1a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 13 additions and 26 deletions

View File

@ -140,16 +140,3 @@ impl Loopable for serde_json::Value {
}
}
}
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

@ -46,6 +46,19 @@ impl<C: 'static + ContextElement + Clone> CloneIntoBoxedContextElement for C {
}
}
impl<C: 'static + ContextElement + PartialEq> CompareContextElement for C {
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)
}
}
impl<'a, 'b> PartialEq<&'b dyn ContextElement> for &'a dyn ContextElement {
fn eq(&self, other: &&'b dyn ContextElement) -> bool {
self.equals(*other)

View File

@ -142,16 +142,3 @@ impl Walkable for String {
Err(WalkError::CantWalk)
}
}
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)
}
}