snarkvm_circuit_environment/traits/from.rs
1// Copyright 2024-2025 Aleo Network Foundation
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
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use crate::{BooleanTrait, FieldTrait, GroupTrait, ScalarTrait};
17
18/// Unary operator for instantiating from a boolean.
19pub trait FromBoolean {
20 type Boolean: BooleanTrait;
21
22 fn from_boolean(boolean: &Self::Boolean) -> Self
23 where
24 Self: Sized;
25}
26
27/// Unary operator for instantiating from bits.
28pub trait FromBits {
29 type Boolean: BooleanTrait;
30
31 fn from_bits_le(bits_le: &[Self::Boolean]) -> Self
32 where
33 Self: Sized;
34
35 fn from_bits_be(bits_be: &[Self::Boolean]) -> Self
36 where
37 Self: Sized;
38}
39
40/// Unary operator for converting from a base field element.
41pub trait FromField {
42 type Field: FieldTrait;
43
44 /// Casts a circuit from a base field element.
45 fn from_field(field: Self::Field) -> Self;
46}
47
48/// Unary operator for converting from a list of base elements.
49pub trait FromFields {
50 type Field: FieldTrait;
51
52 /// Casts a circuit from a list of base field elements.
53 fn from_fields(fields: &[Self::Field]) -> Self;
54}
55
56/// Unary operator for converting from an affine group element.
57pub trait FromGroup {
58 type Group: GroupTrait<Self::Scalar>;
59 type Scalar: ScalarTrait;
60
61 /// Casts a circuit from an affine group element.
62 fn from_group(group: Self::Group) -> Self;
63}