Separating out CastToAny.
This commit is contained in:
@@ -30,9 +30,11 @@ pub trait Loopable {
|
||||
fn get_loop_elements(&self) -> Vec<&dyn ContextElement>;
|
||||
}
|
||||
|
||||
pub trait CompareContextElement {
|
||||
pub trait CastToAny {
|
||||
fn to_any(&self) -> &dyn Any;
|
||||
}
|
||||
|
||||
pub trait CompareContextElement: CastToAny {
|
||||
fn equals(&self, other: &dyn ContextElement) -> bool;
|
||||
}
|
||||
|
||||
@@ -46,19 +48,25 @@ impl<C: 'static + ContextElement + Clone> CloneIntoBoxedContextElement for C {
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: 'static + ContextElement + PartialEq> CompareContextElement for C {
|
||||
impl<C: 'static + ContextElement + PartialEq> CastToAny 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<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)
|
||||
|
||||
Reference in New Issue
Block a user