bellman/
gadgets.rs

1//! Self-contained sub-circuit implementations for various primitives.
2
3pub mod test;
4
5pub mod blake2s;
6pub mod boolean;
7pub mod lookup;
8pub mod multieq;
9pub mod multipack;
10pub mod num;
11pub mod sha256;
12pub mod uint32;
13
14use crate::SynthesisError;
15
16// TODO: This should probably be removed and we
17// should use existing helper methods on `Option`
18// for mapping with an error.
19/// This basically is just an extension to `Option`
20/// which allows for a convenient mapping to an
21/// error on `None`.
22pub trait Assignment<T> {
23    fn get(&self) -> Result<&T, SynthesisError>;
24}
25
26impl<T> Assignment<T> for Option<T> {
27    fn get(&self) -> Result<&T, SynthesisError> {
28        match *self {
29            Some(ref v) => Ok(v),
30            None => Err(SynthesisError::AssignmentMissing),
31        }
32    }
33}