pub trait CondSelectGadget<ConstraintF: Field>: Sized + Clone {
// Required method
fn conditionally_select(
cond: &Boolean<ConstraintF>,
true_value: &Self,
false_value: &Self,
) -> Result<Self, SynthesisError>;
// Provided method
fn conditionally_select_power_of_two_vector(
position: &[Boolean<ConstraintF>],
values: &[Self],
) -> Result<Self, SynthesisError> { ... }
}
Expand description
Generates constraints for selecting between one of two values.
Required Methods§
Sourcefn conditionally_select(
cond: &Boolean<ConstraintF>,
true_value: &Self,
false_value: &Self,
) -> Result<Self, SynthesisError>
fn conditionally_select( cond: &Boolean<ConstraintF>, true_value: &Self, false_value: &Self, ) -> Result<Self, SynthesisError>
If cond == &Boolean::TRUE
, then this returns true_value
; else,
returns false_value
.
§Note
Self::conditionally_select(cond, true_value, false_value)?
can be more
succinctly written as cond.select(&true_value, &false_value)?
.
Provided Methods§
Sourcefn conditionally_select_power_of_two_vector(
position: &[Boolean<ConstraintF>],
values: &[Self],
) -> Result<Self, SynthesisError>
fn conditionally_select_power_of_two_vector( position: &[Boolean<ConstraintF>], values: &[Self], ) -> Result<Self, SynthesisError>
Returns an element of values
whose index in represented by position
.
position
is an array of boolean that represents an unsigned integer in
big endian order.
§Example
To get the 6th element of values
, convert unsigned integer 6 (0b110
)
to position = [True, True, False]
,
and call conditionally_select_power_of_two_vector(position, values)
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.