//! Implementations of common circuit layouters. use std::fmt; use super::{Cell, Chip, Permutation}; use crate::plonk::{Advice, Column, Error, Fixed}; /// Helper trait for implementing a custom [`Layouter`]. /// /// This trait is used for implementing region assignments: /// /// ```ignore /// impl<'a, C: Chip, CS: Assignment + 'a> Layouter for MyLayouter<'a, C, CS> { /// fn assign_region( /// &mut self, /// assignment: impl FnOnce(Region<'_, C>) -> Result<(), Error>, /// ) -> Result<(), Error> { /// let region_index = self.regions.len(); /// self.regions.push(self.current_gate); /// /// let mut region = MyRegion::new(self, region_index); /// { /// let region: &mut dyn RegionLayouter = &mut region; /// assignment(region.into())?; /// } /// self.current_gate += region.row_count; /// /// Ok(()) /// } /// } /// ``` /// /// TODO: It would be great if we could constrain the columns in these types to be /// "logical" columns that are guaranteed to correspond to the chip (and have come from /// `Chip::Config`). pub trait RegionLayouter: fmt::Debug { /// Assign an advice column value (witness) fn assign_advice<'v>( &'v mut self, column: Column, offset: usize, to: &'v mut (dyn FnMut() -> Result + 'v), ) -> Result; /// Assign a fixed value fn assign_fixed<'v>( &'v mut self, column: Column, offset: usize, to: &'v mut (dyn FnMut() -> Result + 'v), ) -> Result; /// Constraint two cells to have the same value. /// /// Returns an error if either of the cells is not within the given permutation. fn constrain_equal( &mut self, permutation: &Permutation, left: Cell, right: Cell, ) -> Result<(), Error>; }