add auto implementation of Pod::equals (#327)
This commit is contained in:
parent
e0d2fce060
commit
335100d1d7
7 changed files with 21 additions and 75 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
use std::{
|
use std::{
|
||||||
any::Any,
|
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
sync::{LazyLock, Mutex},
|
sync::{LazyLock, Mutex},
|
||||||
};
|
};
|
||||||
|
|
@ -193,17 +192,6 @@ impl Pod for EmptyPod {
|
||||||
})
|
})
|
||||||
.expect("serialization to json")
|
.expect("serialization to json")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
fn equals(&self, other: &dyn Pod) -> bool {
|
|
||||||
if let Some(other) = other.as_any().downcast_ref::<EmptyPod>() {
|
|
||||||
self == other
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RecursivePod for EmptyPod {
|
impl RecursivePod for EmptyPod {
|
||||||
|
|
|
||||||
|
|
@ -676,17 +676,6 @@ impl Pod for MainPod {
|
||||||
})
|
})
|
||||||
.expect("serialization to json")
|
.expect("serialization to json")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
fn equals(&self, other: &dyn Pod) -> bool {
|
|
||||||
if let Some(other) = other.as_any().downcast_ref::<MainPod>() {
|
|
||||||
self == other
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RecursivePod for MainPod {
|
impl RecursivePod for MainPod {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
use std::any::Any;
|
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -69,17 +67,6 @@ impl Pod for MockEmptyPod {
|
||||||
fn serialize_data(&self) -> serde_json::Value {
|
fn serialize_data(&self) -> serde_json::Value {
|
||||||
serde_json::Value::Null
|
serde_json::Value::Null
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
fn equals(&self, other: &dyn Pod) -> bool {
|
|
||||||
if let Some(other) = other.as_any().downcast_ref::<MockEmptyPod>() {
|
|
||||||
self == other
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RecursivePod for MockEmptyPod {
|
impl RecursivePod for MockEmptyPod {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// MainPod
|
// MainPod
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::{any::Any, fmt, iter};
|
use std::{fmt, iter};
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -367,17 +367,6 @@ impl Pod for MockMainPod {
|
||||||
})
|
})
|
||||||
.expect("serialization to json")
|
.expect("serialization to json")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
fn equals(&self, other: &dyn Pod) -> bool {
|
|
||||||
if let Some(other) = other.as_any().downcast_ref::<MockMainPod>() {
|
|
||||||
self == other
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RecursivePod for MockMainPod {
|
impl RecursivePod for MockMainPod {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{any::Any, collections::HashMap};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -166,17 +166,6 @@ impl Pod for MockSignedPod {
|
||||||
})
|
})
|
||||||
.expect("serialization to json")
|
.expect("serialization to json")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
fn equals(&self, other: &dyn Pod) -> bool {
|
|
||||||
if let Some(other) = other.as_any().downcast_ref::<MockSignedPod>() {
|
|
||||||
self == other
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{any::Any, collections::HashMap, sync::LazyLock};
|
use std::{collections::HashMap, sync::LazyLock};
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use num_bigint::{BigUint, RandBigInt};
|
use num_bigint::{BigUint, RandBigInt};
|
||||||
|
|
@ -203,17 +203,6 @@ impl Pod for SignedPod {
|
||||||
})
|
})
|
||||||
.expect("serialization to json")
|
.expect("serialization to json")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
fn equals(&self, other: &dyn Pod) -> bool {
|
|
||||||
if let Some(other) = other.as_any().downcast_ref::<SignedPod>() {
|
|
||||||
self == other
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
|
|
@ -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")
|
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 params(&self) -> &Params;
|
||||||
fn verify(&self) -> Result<(), BackendError>;
|
fn verify(&self) -> Result<(), BackendError>;
|
||||||
fn id(&self) -> PodId;
|
fn id(&self) -> PodId;
|
||||||
|
|
@ -808,8 +822,9 @@ pub trait Pod: fmt::Debug + DynClone + Sync + Send + Any {
|
||||||
.collect()
|
.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> {
|
impl PartialEq for Box<dyn Pod> {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue