snarkvm_circuit_program/data/literal/
to_fields.rs

1// Copyright (c) 2019-2025 Provable 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
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 super::*;
17
18impl<A: Aleo> ToFields for Literal<A> {
19    type Field = Field<A>;
20
21    /// Returns the literal as a list of base field elements.
22    fn to_fields(&self) -> Vec<Field<A>> {
23        (&self).to_fields()
24    }
25}
26
27impl<A: Aleo> ToFields for &Literal<A> {
28    type Field = Field<A>;
29
30    /// Returns the literal as a list of base field elements.
31    fn to_fields(&self) -> Vec<Self::Field> {
32        match self {
33            Literal::Address(literal) => vec![literal.to_field()],
34            Literal::Boolean(literal) => vec![Field::from_boolean(literal)],
35            Literal::Field(literal) => vec![literal.clone()],
36            Literal::Group(literal) => vec![literal.to_x_coordinate()],
37            Literal::I8(literal) => vec![literal.to_field()],
38            Literal::I16(literal) => vec![literal.to_field()],
39            Literal::I32(literal) => vec![literal.to_field()],
40            Literal::I64(literal) => vec![literal.to_field()],
41            Literal::I128(literal) => vec![literal.to_field()],
42            Literal::U8(literal) => vec![literal.to_field()],
43            Literal::U16(literal) => vec![literal.to_field()],
44            Literal::U32(literal) => vec![literal.to_field()],
45            Literal::U64(literal) => vec![literal.to_field()],
46            Literal::U128(literal) => vec![literal.to_field()],
47            Literal::Scalar(literal) => vec![literal.to_field()],
48            Literal::Signature(literal) => literal.to_fields(),
49            Literal::String(literal) => literal.to_fields(),
50        }
51    }
52}