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 pub use cast::Cast; 17 pub use cast_lossy::CastLossy; 18 19 mod bytes; 20 mod cast; 21 mod cast_lossy; 22 mod equal; 23 mod from_bits; 24 mod parse; 25 mod sample; 26 mod serialize; 27 mod size_in_bits; 28 mod size_in_bytes; 29 mod to_bits; 30 mod to_type; 31 mod variant; 32 33 use crate::{LiteralType, ProgramID}; 34 use alphavm_console_account::{ComputeKey, PrivateKey, Signature}; 35 use alphavm_console_network::Network; 36 use alphavm_console_types::{Boolean, prelude::*}; 37 38 /// The literal enum represents all supported types in alphavm. 39 #[derive(Clone)] 40 pub enum Literal<N: Network> { 41 /// The Alpha 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 77 macro_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 89 impl_from! { 90 Address Boolean Field Group 91 I8 I16 I32 I64 I128 92 U8 U16 U32 U64 U128 93 Scalar 94 } 95 96 impl<N: Network> From<Signature<N>> for Literal<N> { 97 fn from(value: Signature<N>) -> Self { 98 Literal::Signature(Box::new(value)) 99 } 100 }