pub trait Circuit<F: Fancy> {
type Input;
type Output: Flatten<Item = F::Item>;
// Required method
fn execute(
&self,
backend: &mut F,
inputs: Self::Input,
channel: &mut Channel<'_>,
) -> Result<Self::Output>;
}Expand description
Trait for defining computations over Fancy objects.
A Circuit computation is defined by a Circuit::Input associated type,
a Circuit::Output associated type, and a Circuit::execute method
that maps Circuit::Input to Circuit::Output. The body of
Circuit::execute may use other Circuits internally.
For mapping arbitrary inputs into the correct Circuit input
representation, use the CircuitInputMapper trait.
§Example
Below is a simple circuit computing an add gate. The computation is defined
in execute by directly calling operations on the underlying Fancy
backend (crate::FancyArithmetic in this example).
struct AddCircuit;
impl<F: FancyArithmetic> Circuit<F> for AddCircuit {
type Input = (F::Item, F::Item);
type Output = F::Item;
fn execute(
&self,
backend: &mut F,
inputs: Self::Input,
channel: &mut Channel,
) -> Result<Self::Output> {
Ok(backend.add(&inputs.0, &inputs.1))
}
}Given AddCircuit, any object instantiating the required Fancy traits
can evaluate the circuit by calling AddMany.execute(...).