diff --git a/src/backends/plonky2/emptypod.rs b/src/backends/plonky2/emptypod.rs index ce454a1..8eb44a8 100644 --- a/src/backends/plonky2/emptypod.rs +++ b/src/backends/plonky2/emptypod.rs @@ -1,5 +1,4 @@ use std::{ - any::Any, collections::HashMap, sync::{LazyLock, Mutex}, }; @@ -193,17 +192,6 @@ impl Pod for EmptyPod { }) .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::() { - self == other - } else { - false - } - } } impl RecursivePod for EmptyPod { diff --git a/src/backends/plonky2/mainpod/mod.rs b/src/backends/plonky2/mainpod/mod.rs index 51e750b..aef804a 100644 --- a/src/backends/plonky2/mainpod/mod.rs +++ b/src/backends/plonky2/mainpod/mod.rs @@ -676,17 +676,6 @@ impl Pod for MainPod { }) .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::() { - self == other - } else { - false - } - } } impl RecursivePod for MainPod { diff --git a/src/backends/plonky2/mock/emptypod.rs b/src/backends/plonky2/mock/emptypod.rs index 0525147..3d0bb08 100644 --- a/src/backends/plonky2/mock/emptypod.rs +++ b/src/backends/plonky2/mock/emptypod.rs @@ -1,5 +1,3 @@ -use std::any::Any; - use itertools::Itertools; use crate::{ @@ -69,17 +67,6 @@ impl Pod for MockEmptyPod { fn serialize_data(&self) -> serde_json::Value { 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::() { - self == other - } else { - false - } - } } impl RecursivePod for MockEmptyPod { diff --git a/src/backends/plonky2/mock/mainpod.rs b/src/backends/plonky2/mock/mainpod.rs index 6553fae..2d9bd69 100644 --- a/src/backends/plonky2/mock/mainpod.rs +++ b/src/backends/plonky2/mock/mainpod.rs @@ -2,7 +2,7 @@ // MainPod // -use std::{any::Any, fmt, iter}; +use std::{fmt, iter}; use itertools::Itertools; use serde::{Deserialize, Serialize}; @@ -367,17 +367,6 @@ impl Pod for MockMainPod { }) .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::() { - self == other - } else { - false - } - } } impl RecursivePod for MockMainPod { diff --git a/src/backends/plonky2/mock/signedpod.rs b/src/backends/plonky2/mock/signedpod.rs index 232ed0f..2e2252f 100644 --- a/src/backends/plonky2/mock/signedpod.rs +++ b/src/backends/plonky2/mock/signedpod.rs @@ -1,4 +1,4 @@ -use std::{any::Any, collections::HashMap}; +use std::collections::HashMap; use itertools::Itertools; use serde::{Deserialize, Serialize}; @@ -166,17 +166,6 @@ impl Pod for MockSignedPod { }) .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::() { - self == other - } else { - false - } - } } #[cfg(test)] diff --git a/src/backends/plonky2/signedpod.rs b/src/backends/plonky2/signedpod.rs index cd5d6e1..b8f0637 100644 --- a/src/backends/plonky2/signedpod.rs +++ b/src/backends/plonky2/signedpod.rs @@ -1,4 +1,4 @@ -use std::{any::Any, collections::HashMap, sync::LazyLock}; +use std::{collections::HashMap, sync::LazyLock}; use itertools::Itertools; use num_bigint::{BigUint, RandBigInt}; @@ -203,17 +203,6 @@ impl Pod for SignedPod { }) .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::() { - self == other - } else { - false - } - } } #[cfg(test)] diff --git a/src/middleware/mod.rs b/src/middleware/mod.rs index 83ca711..4689946 100644 --- a/src/middleware/mod.rs +++ b/src/middleware/mod.rs @@ -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 EqualsAny for T { + fn equals_any(&self, other: &dyn Any) -> bool { + if let Some(o) = other.downcast_ref::() { + 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 { fn eq(&self, other: &Self) -> bool {