snarkvm_console_program/data/value/
mod.rs1mod bytes;
17mod equal;
18mod find;
19mod parse;
20mod serialize;
21mod to_bits;
22mod to_bits_raw;
23mod to_fields;
24mod to_fields_raw;
25
26use crate::{Access, Argument, Entry, Future, Literal, Plaintext, Record};
27use snarkvm_console_network::Network;
28use snarkvm_console_types::prelude::*;
29
30#[derive(Clone)]
31pub enum Value<N: Network> {
32 Plaintext(Plaintext<N>),
34 Record(Record<N, Plaintext<N>>),
36 Future(Future<N>),
38}
39
40impl<N: Network> From<Literal<N>> for Value<N> {
41 fn from(literal: Literal<N>) -> Self {
43 Self::Plaintext(Plaintext::from(literal))
44 }
45}
46
47impl<N: Network> From<&Literal<N>> for Value<N> {
48 fn from(literal: &Literal<N>) -> Self {
50 Self::from(Plaintext::from(literal))
51 }
52}
53
54impl<N: Network> From<Plaintext<N>> for Value<N> {
55 fn from(plaintext: Plaintext<N>) -> Self {
57 Self::Plaintext(plaintext)
58 }
59}
60
61impl<N: Network> From<&Plaintext<N>> for Value<N> {
62 fn from(plaintext: &Plaintext<N>) -> Self {
64 Self::from(plaintext.clone())
65 }
66}
67
68impl<N: Network> From<Record<N, Plaintext<N>>> for Value<N> {
69 fn from(record: Record<N, Plaintext<N>>) -> Self {
71 Self::Record(record)
72 }
73}
74
75impl<N: Network> From<&Record<N, Plaintext<N>>> for Value<N> {
76 fn from(record: &Record<N, Plaintext<N>>) -> Self {
78 Self::from(record.clone())
79 }
80}
81
82impl<N: Network> From<Future<N>> for Value<N> {
83 fn from(future: Future<N>) -> Self {
85 Self::Future(future)
86 }
87}
88
89impl<N: Network> From<&Future<N>> for Value<N> {
90 fn from(future: &Future<N>) -> Self {
92 Self::from(future.clone())
93 }
94}
95
96impl<N: Network> From<Argument<N>> for Value<N> {
97 fn from(argument: Argument<N>) -> Self {
99 match argument {
100 Argument::Plaintext(plaintext) => Self::Plaintext(plaintext),
101 Argument::Future(future) => Self::Future(future),
102 }
103 }
104}
105
106impl<N: Network> From<&Argument<N>> for Value<N> {
107 fn from(argument: &Argument<N>) -> Self {
109 Self::from(argument.clone())
110 }
111}
112
113impl<N: Network> From<&Value<N>> for Value<N> {
114 fn from(value: &Value<N>) -> Self {
116 value.clone()
117 }
118}
119
120impl<N: Network> TryFrom<Result<Value<N>>> for Value<N> {
121 type Error = Error;
122
123 fn try_from(value: Result<Value<N>>) -> Result<Self> {
125 value
126 }
127}
128
129impl<N: Network> TryFrom<String> for Value<N> {
130 type Error = Error;
131
132 fn try_from(value: String) -> Result<Self> {
134 Self::from_str(&value)
135 }
136}
137
138impl<N: Network> TryFrom<&String> for Value<N> {
139 type Error = Error;
140
141 fn try_from(value: &String) -> Result<Self> {
143 Self::from_str(value)
144 }
145}
146
147impl<N: Network> TryFrom<&str> for Value<N> {
148 type Error = Error;
149
150 fn try_from(value: &str) -> Result<Self> {
152 Self::from_str(value)
153 }
154}