pub struct VarAllocator<T> { /* private fields */ }Expand description
Allocator for wire variables.
Mints a fresh wire on request and records the values of the wires that
have been assigned, which are the relation’s public inputs. Handles are
reference counted, so relations of different widths can share one
namespace through PermutationRelation::with_allocator.
Implementations§
Source§impl<T: Unit> VarAllocator<T>
impl<T: Unit> VarAllocator<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
An allocator holding only FieldVar::ZERO, assigned to T::ZERO.
Sourcepub fn allocate_var(&self) -> FieldVar
pub fn allocate_var(&self) -> FieldVar
Allocates one wire, unassigned.
§Panics
Panics when FieldVar::MAX_COUNT wires have already been allocated.
Sourcepub fn allocate_vars<const N: usize>(&self) -> [FieldVar; N]
pub fn allocate_vars<const N: usize>(&self) -> [FieldVar; N]
Allocates N wires, so let [x, y] = allocator.allocate_vars()
allocates two at once.
Sourcepub fn allocate_vars_vec(&self, count: usize) -> Vec<FieldVar>
pub fn allocate_vars_vec(&self, count: usize) -> Vec<FieldVar>
Allocates count wires.
§Panics
Panics, before allocating anything, if the total would exceed
FieldVar::MAX_COUNT.
Sourcepub fn allocate_var_with(&self, value: T) -> FieldVarwhere
T: PartialEq,
pub fn allocate_var_with(&self, value: T) -> FieldVarwhere
T: PartialEq,
Allocates one wire and assigns it value.
Sourcepub fn allocate_vars_with<const N: usize>(
&self,
values: &[T; N],
) -> [FieldVar; N]where
T: PartialEq,
pub fn allocate_vars_with<const N: usize>(
&self,
values: &[T; N],
) -> [FieldVar; N]where
T: PartialEq,
Allocates N wires and assigns them values.
Sourcepub fn allocate_vars_vec_with(&self, values: &[T]) -> Vec<FieldVar>where
T: PartialEq,
pub fn allocate_vars_vec_with(&self, values: &[T]) -> Vec<FieldVar>where
T: PartialEq,
Allocates one wire per element of values and assigns them.
Sourcepub fn vars_count(&self) -> usize
pub fn vars_count(&self) -> usize
The number of wires allocated so far, FieldVar::ZERO included.
Sourcepub fn is_allocated(&self, var: FieldVar) -> bool
pub fn is_allocated(&self, var: FieldVar) -> bool
Whether var was allocated by this allocator.
Sourcepub fn set_var(&self, var: FieldVar, value: T)where
T: PartialEq,
pub fn set_var(&self, var: FieldVar, value: T)where
T: PartialEq,
Assigns value to var, making the wire public.
§Panics
Panics if var was not allocated by this allocator, or if it already
holds a different value.
Sourcepub fn set_vars<Var, Val>(
&self,
vars: impl IntoIterator<Item = Var>,
values: impl IntoIterator<Item = Val>,
)
pub fn set_vars<Var, Val>( &self, vars: impl IntoIterator<Item = Var>, values: impl IntoIterator<Item = Val>, )
Assigns each wire of vars the corresponding element of values.
§Panics
Panics if the two iterators differ in length, or as Self::set_var
does for any pair.
Sourcepub fn public_vars(&self) -> Vec<(FieldVar, T)>
pub fn public_vars(&self) -> Vec<(FieldVar, T)>
The assigned wires and their values, in index order.
Trait Implementations§
Source§impl<T> Clone for VarAllocator<T>
impl<T> Clone for VarAllocator<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for VarAllocator<T>
impl<T> !UnwindSafe for VarAllocator<T>
impl<T> Freeze for VarAllocator<T>
impl<T> Send for VarAllocator<T>
impl<T> Sync for VarAllocator<T>
impl<T> Unpin for VarAllocator<T>
impl<T> UnsafeUnpin for VarAllocator<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more