Skip to content

Commit 10a9d81

Browse files
authored
Make closure of challenge phase FnOnce. (#276)
It allows for the challenge phase to accept closures that take some more context, e.g. moving non-Clone values in the challenge closure. This works in stable since Rust 1.35; cfr. rust-lang/rust#28796. This closes issue #244.
1 parent fdb68ff commit 10a9d81

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/r1cs/constraint_system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub trait RandomizableConstraintSystem: ConstraintSystem {
106106
/// ```
107107
fn specify_randomized_constraints<F>(&mut self, callback: F) -> Result<(), R1CSError>
108108
where
109-
F: 'static + Fn(&mut Self::RandomizedCS) -> Result<(), R1CSError>;
109+
F: 'static + FnOnce(&mut Self::RandomizedCS) -> Result<(), R1CSError>;
110110
}
111111

112112
/// Represents a constraint system in the second phase:

src/r1cs/prover.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub struct Prover<'g, T: BorrowMut<Transcript>> {
3838

3939
/// This list holds closures that will be called in the second phase of the protocol,
4040
/// when non-randomized variables are committed.
41-
deferred_constraints: Vec<Box<dyn Fn(&mut RandomizingProver<'g, T>) -> Result<(), R1CSError>>>,
41+
deferred_constraints:
42+
Vec<Box<dyn FnOnce(&mut RandomizingProver<'g, T>) -> Result<(), R1CSError>>>,
4243

4344
/// Index of a pending multiplier that's not fully assigned yet.
4445
pending_multiplier: Option<usize>,
@@ -188,7 +189,7 @@ impl<'g, T: BorrowMut<Transcript>> RandomizableConstraintSystem for Prover<'g, T
188189

189190
fn specify_randomized_constraints<F>(&mut self, callback: F) -> Result<(), R1CSError>
190191
where
191-
F: 'static + Fn(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
192+
F: 'static + FnOnce(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
192193
{
193194
self.deferred_constraints.push(Box::new(callback));
194195
Ok(())

src/r1cs/verifier.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ pub struct Verifier<T: BorrowMut<Transcript>> {
4444
/// when non-randomized variables are committed.
4545
/// After that, the option will flip to None and additional calls to `randomize_constraints`
4646
/// will invoke closures immediately.
47-
deferred_constraints: Vec<Box<dyn Fn(&mut RandomizingVerifier<T>) -> Result<(), R1CSError>>>,
47+
deferred_constraints:
48+
Vec<Box<dyn FnOnce(&mut RandomizingVerifier<T>) -> Result<(), R1CSError>>>,
4849

4950
/// Index of a pending multiplier that's not fully assigned yet.
5051
pending_multiplier: Option<usize>,
@@ -140,7 +141,7 @@ impl<T: BorrowMut<Transcript>> RandomizableConstraintSystem for Verifier<T> {
140141

141142
fn specify_randomized_constraints<F>(&mut self, callback: F) -> Result<(), R1CSError>
142143
where
143-
F: 'static + Fn(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
144+
F: 'static + FnOnce(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
144145
{
145146
self.deferred_constraints.push(Box::new(callback));
146147
Ok(())

0 commit comments

Comments
 (0)