Skip to content

Commit 9ec3dd6

Browse files
committed
Make closure of challenge phase FnOnce.
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 dalek-cryptography#244.
1 parent ee8cc66 commit 9ec3dd6

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/r1cs/constraint_system.rs

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

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

src/r1cs/prover.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct Prover<'t, 'g> {
4444

4545
/// This list holds closures that will be called in the second phase of the protocol,
4646
/// when non-randomized variables are committed.
47-
deferred_constraints: Vec<Box<Fn(&mut RandomizingProver<'t, 'g>) -> Result<(), R1CSError>>>,
47+
deferred_constraints: Vec<Box<FnOnce(&mut RandomizingProver<'t, 'g>) -> Result<(), R1CSError>>>,
4848

4949
/// Index of a pending multiplier that's not fully assigned yet.
5050
pending_multiplier: Option<usize>,
@@ -170,7 +170,7 @@ impl<'t, 'g> RandomizableConstraintSystem for Prover<'t, 'g> {
170170

171171
fn specify_randomized_constraints<F>(&mut self, callback: F) -> Result<(), R1CSError>
172172
where
173-
F: 'static + Fn(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
173+
F: 'static + FnOnce(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
174174
{
175175
self.deferred_constraints.push(Box::new(callback));
176176
Ok(())

src/r1cs/verifier.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct Verifier<'t> {
4242
/// when non-randomized variables are committed.
4343
/// After that, the option will flip to None and additional calls to `randomize_constraints`
4444
/// will invoke closures immediately.
45-
deferred_constraints: Vec<Box<Fn(&mut RandomizingVerifier<'t>) -> Result<(), R1CSError>>>,
45+
deferred_constraints: Vec<Box<FnOnce(&mut RandomizingVerifier<'t>) -> Result<(), R1CSError>>>,
4646

4747
/// Index of a pending multiplier that's not fully assigned yet.
4848
pending_multiplier: Option<usize>,
@@ -129,7 +129,7 @@ impl<'t> RandomizableConstraintSystem for Verifier<'t> {
129129

130130
fn specify_randomized_constraints<F>(&mut self, callback: F) -> Result<(), R1CSError>
131131
where
132-
F: 'static + Fn(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
132+
F: 'static + FnOnce(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
133133
{
134134
self.deferred_constraints.push(Box::new(callback));
135135
Ok(())

0 commit comments

Comments
 (0)