mod.rs
1 // Copyright (c) 2025-2026 ACDC Network 2 // This file is part of the alphavm library. 3 // 4 // Alpha Chain | Delta Chain Protocol 5 // International Monetary Graphite. 6 // 7 // Derived from Aleo (https://aleo.org) and ProvableHQ (https://provable.com). 8 // They built world-class ZK infrastructure. We installed the EASY button. 9 // Their cryptography: elegant. Our modifications: bureaucracy-compatible. 10 // Original brilliance: theirs. Robert's Rules: ours. Bugs: definitely ours. 11 // 12 // Original Aleo/ProvableHQ code subject to Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0 13 // All modifications and new work: CC0 1.0 Universal Public Domain Dedication. 14 // No rights reserved. No permission required. No warranty. No refunds. 15 // 16 // https://creativecommons.org/publicdomain/zero/1.0/ 17 // SPDX-License-Identifier: CC0-1.0 18 19 mod bytes; 20 mod equal; 21 mod find; 22 mod parse; 23 mod serialize; 24 mod to_bits; 25 mod to_bits_raw; 26 mod to_fields; 27 mod to_fields_raw; 28 29 use crate::{Access, Argument, Entry, Future, Literal, Plaintext, Record}; 30 use alphavm_console_network::Network; 31 use alphavm_console_types::prelude::*; 32 33 #[derive(Clone)] 34 pub enum Value<N: Network> { 35 /// A plaintext value. 36 Plaintext(Plaintext<N>), 37 /// A record value. 38 Record(Record<N, Plaintext<N>>), 39 /// A future. 40 Future(Future<N>), 41 } 42 43 impl<N: Network> From<Literal<N>> for Value<N> { 44 /// Initializes the value from a literal. 45 fn from(literal: Literal<N>) -> Self { 46 Self::Plaintext(Plaintext::from(literal)) 47 } 48 } 49 50 impl<N: Network> From<&Literal<N>> for Value<N> { 51 /// Initializes the value from a literal. 52 fn from(literal: &Literal<N>) -> Self { 53 Self::from(Plaintext::from(literal)) 54 } 55 } 56 57 impl<N: Network> From<Plaintext<N>> for Value<N> { 58 /// Initializes the value from a plaintext. 59 fn from(plaintext: Plaintext<N>) -> Self { 60 Self::Plaintext(plaintext) 61 } 62 } 63 64 impl<N: Network> From<&Plaintext<N>> for Value<N> { 65 /// Initializes the value from a plaintext. 66 fn from(plaintext: &Plaintext<N>) -> Self { 67 Self::from(plaintext.clone()) 68 } 69 } 70 71 impl<N: Network> From<Record<N, Plaintext<N>>> for Value<N> { 72 /// Initializes the value from a record. 73 fn from(record: Record<N, Plaintext<N>>) -> Self { 74 Self::Record(record) 75 } 76 } 77 78 impl<N: Network> From<&Record<N, Plaintext<N>>> for Value<N> { 79 /// Initializes the value from a record. 80 fn from(record: &Record<N, Plaintext<N>>) -> Self { 81 Self::from(record.clone()) 82 } 83 } 84 85 impl<N: Network> From<Future<N>> for Value<N> { 86 /// Initializes the value from a future. 87 fn from(future: Future<N>) -> Self { 88 Self::Future(future) 89 } 90 } 91 92 impl<N: Network> From<&Future<N>> for Value<N> { 93 /// Initializes the value from a future. 94 fn from(future: &Future<N>) -> Self { 95 Self::from(future.clone()) 96 } 97 } 98 99 impl<N: Network> From<Argument<N>> for Value<N> { 100 /// Initializes the value from an argument. 101 fn from(argument: Argument<N>) -> Self { 102 match argument { 103 Argument::Plaintext(plaintext) => Self::Plaintext(plaintext), 104 Argument::Future(future) => Self::Future(future), 105 } 106 } 107 } 108 109 impl<N: Network> From<&Argument<N>> for Value<N> { 110 /// Initializes the value from an argument. 111 fn from(argument: &Argument<N>) -> Self { 112 Self::from(argument.clone()) 113 } 114 } 115 116 impl<N: Network> From<&Value<N>> for Value<N> { 117 /// Returns a clone of the value. 118 fn from(value: &Value<N>) -> Self { 119 value.clone() 120 } 121 } 122 123 impl<N: Network> TryFrom<Result<Value<N>>> for Value<N> { 124 type Error = Error; 125 126 /// Initializes a value from a result. 127 fn try_from(value: Result<Value<N>>) -> Result<Self> { 128 value 129 } 130 } 131 132 impl<N: Network> TryFrom<String> for Value<N> { 133 type Error = Error; 134 135 /// Initializes a value from a string. 136 fn try_from(value: String) -> Result<Self> { 137 Self::from_str(&value) 138 } 139 } 140 141 impl<N: Network> TryFrom<&String> for Value<N> { 142 type Error = Error; 143 144 /// Initializes a value from a string. 145 fn try_from(value: &String) -> Result<Self> { 146 Self::from_str(value) 147 } 148 } 149 150 impl<N: Network> TryFrom<&str> for Value<N> { 151 type Error = Error; 152 153 /// Initializes a value from a string. 154 fn try_from(value: &str) -> Result<Self> { 155 Self::from_str(value) 156 } 157 }