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