mod.rs
 1  // Copyright (c) 2019-2025 Alpha-Delta Network Inc.
 2  // This file is part of the alphavm 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  
16  mod bytes;
17  mod parse;
18  mod serialize;
19  mod size_in_bits;
20  mod size_in_bytes;
21  
22  use alphavm_console_account::Signature;
23  use alphavm_console_network::prelude::*;
24  use alphavm_console_types::{Boolean, prelude::*};
25  
26  use core::fmt::{self, Debug, Display};
27  use enum_iterator::Sequence;
28  use num_derive::FromPrimitive;
29  use num_traits::FromPrimitive;
30  
31  #[derive(Copy, Clone, PartialEq, Eq, Hash, FromPrimitive, Sequence)]
32  pub enum LiteralType {
33      /// The Alpha address type.
34      Address,
35      /// The boolean type.
36      Boolean,
37      /// The field type (base field).
38      Field,
39      /// The group type (affine).
40      Group,
41      /// The 8-bit signed integer type.
42      I8,
43      /// The 16-bit signed integer type.
44      I16,
45      /// The 32-bit signed integer type.
46      I32,
47      /// The 64-bit signed integer type.
48      I64,
49      /// The 128-bit signed integer type.
50      I128,
51      /// The 8-bit unsigned integer type.
52      U8,
53      /// The 16-bit unsigned integer type.
54      U16,
55      /// The 32-bit unsigned integer type.
56      U32,
57      /// The 64-bit unsigned integer type.
58      U64,
59      /// The 128-bit unsigned integer type.
60      U128,
61      /// The scalar type (scalar field).
62      Scalar,
63      /// The signature type.
64      Signature,
65      /// The string type.
66      String,
67  }
68  
69  impl LiteralType {
70      /// Returns the literal type name.
71      pub const fn type_name(&self) -> &str {
72          match self {
73              Self::Address => "address",
74              Self::Boolean => "boolean",
75              Self::Field => "field",
76              Self::Group => "group",
77              Self::I8 => "i8",
78              Self::I16 => "i16",
79              Self::I32 => "i32",
80              Self::I64 => "i64",
81              Self::I128 => "i128",
82              Self::U8 => "u8",
83              Self::U16 => "u16",
84              Self::U32 => "u32",
85              Self::U64 => "u64",
86              Self::U128 => "u128",
87              Self::Scalar => "scalar",
88              Self::Signature => "signature",
89              Self::String => "string",
90          }
91      }
92  
93      /// Returns the unique numeric identifier for the literal type.
94      pub fn type_id(&self) -> u8 {
95          *self as u8
96      }
97  }