snarkvm_r1cs/assignment.rs
1// Copyright (C) 2019-2023 Aleo Systems Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7// http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::errors::SynthesisError;
16
17pub trait Assignment<T> {
18 fn get(self) -> Result<T, SynthesisError>;
19
20 fn get_ref(&self) -> Result<&T, SynthesisError>;
21}
22
23impl<T> Assignment<T> for Option<T> {
24 fn get(self) -> Result<T, SynthesisError> {
25 match self {
26 Some(v) => Ok(v),
27 None => Err(SynthesisError::AssignmentMissing),
28 }
29 }
30
31 fn get_ref(&self) -> Result<&T, SynthesisError> {
32 match *self {
33 Some(ref v) => Ok(v),
34 None => Err(SynthesisError::AssignmentMissing),
35 }
36 }
37}