snarkvm_console_program/data/literal/
mod.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
16pub use cast::Cast;
17pub use cast_lossy::CastLossy;
18
19mod bytes;
20mod cast;
21mod cast_lossy;
22mod equal;
23mod from_bits;
24mod parse;
25mod sample;
26mod serialize;
27mod size_in_bits;
28mod size_in_bytes;
29mod to_bits;
30mod to_type;
31mod variant;
32
33use crate::{LiteralType, ProgramID};
34use snarkvm_console_account::{ComputeKey, PrivateKey, Signature};
35use snarkvm_console_network::Network;
36use snarkvm_console_types::{Boolean, prelude::*};
37
38/// The literal enum represents all supported types in snarkVM.
39#[derive(Clone)]
40pub enum Literal<N: Network> {
41    /// The Aleo address type.
42    Address(Address<N>),
43    /// The boolean type.
44    Boolean(Boolean<N>),
45    /// The field type.
46    Field(Field<N>),
47    /// The group type.
48    Group(Group<N>),
49    /// The 8-bit signed integer type.
50    I8(I8<N>),
51    /// The 16-bit signed integer type.
52    I16(I16<N>),
53    /// The 32-bit signed integer type.
54    I32(I32<N>),
55    /// The 64-bit signed integer type.
56    I64(I64<N>),
57    /// The 128-bit signed integer type.
58    I128(I128<N>),
59    /// The 8-bit unsigned integer type.
60    U8(U8<N>),
61    /// The 16-bit unsigned integer type.
62    U16(U16<N>),
63    /// The 32-bit unsigned integer type.
64    U32(U32<N>),
65    /// The 64-bit unsigned integer type.
66    U64(U64<N>),
67    /// The 128-bit unsigned integer type.
68    U128(U128<N>),
69    /// The scalar type.
70    Scalar(Scalar<N>),
71    /// The signature type.
72    Signature(Box<Signature<N>>),
73    /// The string type.
74    String(StringType<N>),
75}
76
77macro_rules! impl_from {
78    ($($name: ident)*) => {
79        $(
80            impl<N: Network> From<$name<N>> for Literal<N> {
81                fn from(value: $name<N>) -> Self {
82                    Literal::$name(value)
83                }
84            }
85        )*
86    };
87}
88
89impl_from! {
90    Address Boolean Field Group
91    I8 I16 I32 I64 I128
92    U8 U16 U32 U64 U128
93    Scalar
94}
95
96impl<N: Network> From<Signature<N>> for Literal<N> {
97    fn from(value: Signature<N>) -> Self {
98        Literal::Signature(Box::new(value))
99    }
100}