Skip to content

Commit ae1a1c4

Browse files
committed
make Pod derive from Any
1 parent 26a6b2d commit ae1a1c4

File tree

6 files changed

+7
-45
lines changed

6 files changed

+7
-45
lines changed

src/backends/plonky2/mainpod/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,7 @@ impl PodProver for Prover {
293293
.signed_pods
294294
.iter()
295295
.map(|p| {
296-
let p = p
297-
.as_any()
298-
.downcast_ref::<SignedPod>()
296+
let p = (*p as &dyn Any).downcast_ref::<SignedPod>()
299297
.expect("type SignedPod");
300298
p.clone()
301299
})
@@ -404,13 +402,6 @@ impl Pod for MainPod {
404402
.collect()
405403
}
406404

407-
fn into_any(self: Box<Self>) -> Box<dyn Any> {
408-
self
409-
}
410-
fn as_any(&self) -> &dyn Any {
411-
self
412-
}
413-
414405
fn serialized_proof(&self) -> String {
415406
todo!()
416407
}

src/backends/plonky2/mock/mainpod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// MainPod
33
//
44

5-
use std::{any::Any, fmt};
5+
use std::fmt;
66

77
use anyhow::{anyhow, Result};
88

@@ -274,13 +274,6 @@ impl Pod for MockMainPod {
274274
.collect()
275275
}
276276

277-
fn into_any(self: Box<Self>) -> Box<dyn Any> {
278-
self
279-
}
280-
fn as_any(&self) -> &dyn Any {
281-
self
282-
}
283-
284277
fn serialized_proof(&self) -> String {
285278
todo!()
286279
// BASE64_STANDARD.encode(serde_json::to_string(self).unwrap())

src/backends/plonky2/mock/signedpod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{any::Any, collections::HashMap};
1+
use std::collections::HashMap;
22

33
use anyhow::{anyhow, Result};
44
use itertools::Itertools;
@@ -122,13 +122,6 @@ impl Pod for MockSignedPod {
122122
.collect()
123123
}
124124

125-
fn into_any(self: Box<Self>) -> Box<dyn Any> {
126-
self
127-
}
128-
fn as_any(&self) -> &dyn Any {
129-
self
130-
}
131-
132125
fn serialized_proof(&self) -> String {
133126
self.signature.to_string()
134127
}

src/backends/plonky2/signedpod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{any::Any, collections::HashMap};
1+
use std::collections::HashMap;
22

33
use anyhow::{anyhow, Result};
44
use itertools::Itertools;
@@ -101,13 +101,6 @@ impl Pod for SignedPod {
101101
.collect()
102102
}
103103

104-
fn into_any(self: Box<Self>) -> Box<dyn Any> {
105-
self
106-
}
107-
fn as_any(&self) -> &dyn Any {
108-
self
109-
}
110-
111104
fn serialized_proof(&self) -> String {
112105
let mut buffer = Vec::new();
113106
use plonky2::util::serialization::Write;
@@ -140,7 +133,7 @@ pub mod tests {
140133
let sk = SecretKey::new_rand();
141134
let mut signer = Signer(sk);
142135
let pod = pod.sign(&mut signer).unwrap();
143-
let pod = pod.pod.into_any().downcast::<SignedPod>().unwrap();
136+
let pod = (pod.pod as Box<dyn Any>).downcast::<SignedPod>().unwrap();
144137

145138
pod.verify()?;
146139
println!("id: {}", pod.id());

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(clippy::get_first)]
2+
#![feature(trait_upcasting)]
23

34
pub mod backends;
45
pub mod constants;

src/middleware/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ impl Params {
487487
}
488488
}
489489

490-
pub trait Pod: fmt::Debug + DynClone {
490+
pub trait Pod: fmt::Debug + DynClone + Any {
491491
fn verify(&self) -> Result<()>;
492492
fn id(&self) -> PodId;
493493
fn pub_statements(&self) -> Vec<Statement>;
@@ -501,9 +501,6 @@ pub trait Pod: fmt::Debug + DynClone {
501501
})
502502
.collect()
503503
}
504-
// Used for downcasting
505-
fn into_any(self: Box<Self>) -> Box<dyn Any>;
506-
fn as_any(&self) -> &dyn Any;
507504
// Front-end Pods keep references to middleware Pods. Most of the
508505
// middleware data can be derived directly from front-end data, but the
509506
// "proof" data is only created at the point of proving/signing, and
@@ -537,12 +534,6 @@ impl Pod for NonePod {
537534
fn pub_statements(&self) -> Vec<Statement> {
538535
Vec::new()
539536
}
540-
fn into_any(self: Box<Self>) -> Box<dyn Any> {
541-
self
542-
}
543-
fn as_any(&self) -> &dyn Any {
544-
self
545-
}
546537
fn serialized_proof(&self) -> String {
547538
"".to_string()
548539
}

0 commit comments

Comments
 (0)