add auto implementation of Pod::equals (#327)

This commit is contained in:
Daniel Gulotta 2025-07-01 11:09:35 -07:00 committed by GitHub
parent e0d2fce060
commit 335100d1d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 21 additions and 75 deletions

View file

@ -776,7 +776,21 @@ pub fn normalize_statement(statement: &Statement, self_id: PodId) -> Statement {
Statement::from_args(predicate, args).expect("statement was valid before normalization")
}
pub trait Pod: fmt::Debug + DynClone + Sync + Send + Any {
pub trait EqualsAny {
fn equals_any(&self, other: &dyn Any) -> bool;
}
impl<T: Any + Eq> EqualsAny for T {
fn equals_any(&self, other: &dyn Any) -> bool {
if let Some(o) = other.downcast_ref::<T>() {
self == o
} else {
false
}
}
}
pub trait Pod: fmt::Debug + DynClone + Sync + Send + Any + EqualsAny {
fn params(&self) -> &Params;
fn verify(&self) -> Result<(), BackendError>;
fn id(&self) -> PodId;
@ -808,8 +822,9 @@ pub trait Pod: fmt::Debug + DynClone + Sync + Send + Any {
.collect()
}
fn as_any(&self) -> &dyn Any;
fn equals(&self, other: &dyn Pod) -> bool;
fn equals(&self, other: &dyn Pod) -> bool {
self.equals_any(other as &dyn Any)
}
}
impl PartialEq for Box<dyn Pod> {
fn eq(&self, other: &Self) -> bool {