pub struct Value<V> { /* private fields */ }
Expand description

A value that might exist within a circuit.

This behaves like Option<V> but differs in two key ways:

  • It does not expose the enum cases, or provide an Option::unwrap equivalent. This helps to ensure that unwitnessed values correctly propagate.
  • It provides pass-through implementations of common traits such as Add and Mul, for improved usability.

Implementations

Constructs an unwitnessed value.

Constructs a known value.

Examples
use halo2_proofs::circuit::Value;

let v = Value::known(37);

Converts from &Value<V> to Value<&V>.

Converts from &mut Value<V> to Value<&mut V>.

Enforces an assertion on the contained value, if known.

The assertion is ignored if self is Value::unknown(). Do not try to enforce circuit constraints with this method!

Panics

Panics if f returns false.

Checks the contained value for an error condition, if known.

The error check is ignored if self is Value::unknown(). Do not try to enforce circuit constraints with this method!

Maps a Value<V> to Value<W> by applying a function to the contained value.

Returns Value::unknown() if the value is Value::unknown(), otherwise calls f with the wrapped value and returns the result.

Zips self with another Value.

If self is Value::known(s) and other is Value::known(o), this method returns Value::known((s, o)). Otherwise, Value::unknown() is returned.

Unzips a value containing a tuple of two values.

If self is Value::known((a, b)), this method returns (Value::known(a), Value::known(b)). Otherwise, (Value::unknown(), Value::unknown())` is returned.

Maps a Value<&V> to a Value<V> by copying the contents of the value.

Maps a Value<&V> to a Value<V> by cloning the contents of the value.

Maps a Value<&mut V> to a Value<V> by copying the contents of the value.

Maps a Value<&mut V> to a Value<V> by cloning the contents of the value.

Transposes a Value<[V; LEN]> into a [Value<V>; LEN].

Value::unknown() will be mapped to [Value::unknown(); LEN].

Transposes a Value<impl IntoIterator<Item = V>> into a Vec<Value<V>>.

Value::unknown() will be mapped to vec![Value::unknown(); length].

Panics

Panics if self is Value::known(values) and values.len() != length.

Returns the field element corresponding to this value.

Returns the field element corresponding to this value.

Doubles this field element.

Examples

If you have a Value<F: Field>, convert it to Value<Assigned<F>> first:

use halo2_proofs::{circuit::Value, plonk::Assigned};

let v = Value::known(F::from(2));
let v: Value<Assigned<F>> = v.into();
v.double();

Squares this field element.

Cubes this field element.

Inverts this assigned value (taking the inverse of zero to be zero).

Evaluates this value directly, performing an unbatched inversion if necessary.

If the denominator is zero, the returned value is zero.

Trait Implementations

The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.

Takes each element in the Iterator: if it is Value::unknown(), no further elements are taken, and the Value::unknown() is returned. Should no Value::unknown() occur, a container of type V containing the values of each Value is returned.

The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts self into T using Into<T>. Read more
Causes self to use its Binary implementation when Debug-formatted.
Causes self to use its Display implementation when Debug-formatted. Read more
Causes self to use its LowerExp implementation when Debug-formatted. Read more
Causes self to use its LowerHex implementation when Debug-formatted. Read more
Causes self to use its Octal implementation when Debug-formatted.
Causes self to use its Pointer implementation when Debug-formatted. Read more
Causes self to use its UpperExp implementation when Debug-formatted. Read more
Causes self to use its UpperHex implementation when Debug-formatted. Read more
Formats each item in a sequence. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function. Read more
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more
The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Attempts to convert self into T using TryInto<T>. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more