snarkvm_circuit_program/data/future/
argument.rs1use super::*;
17
18#[derive(Clone)]
20pub enum Argument<A: Aleo> {
21 Plaintext(Plaintext<A>),
23 Future(Future<A>),
25 DynamicFuture(DynamicFuture<A>),
27}
28
29impl<A: Aleo> Inject for Argument<A> {
30 type Primitive = console::Argument<A::Network>;
31
32 fn new(mode: Mode, value: Self::Primitive) -> Self {
34 match value {
35 console::Argument::Plaintext(plaintext) => Self::Plaintext(Inject::new(mode, plaintext)),
36 console::Argument::Future(future) => Self::Future(Inject::new(mode, future)),
37 console::Argument::DynamicFuture(dynamic_future) => Self::DynamicFuture(Inject::new(mode, dynamic_future)),
38 }
39 }
40}
41
42impl<A: Aleo> Eject for Argument<A> {
43 type Primitive = console::Argument<A::Network>;
44
45 fn eject_mode(&self) -> Mode {
47 match self {
48 Self::Plaintext(plaintext) => plaintext.eject_mode(),
49 Self::Future(future) => future.eject_mode(),
50 Self::DynamicFuture(dynamic_future) => dynamic_future.eject_mode(),
51 }
52 }
53
54 fn eject_value(&self) -> Self::Primitive {
56 match self {
57 Self::Plaintext(plaintext) => Self::Primitive::Plaintext(plaintext.eject_value()),
58 Self::Future(future) => Self::Primitive::Future(future.eject_value()),
59 Self::DynamicFuture(dynamic_future) => Self::Primitive::DynamicFuture(dynamic_future.eject_value()),
60 }
61 }
62}
63
64impl<A: Aleo> Equal<Self> for Argument<A> {
65 type Output = Boolean<A>;
66
67 fn is_equal(&self, other: &Self) -> Self::Output {
69 match (self, other) {
70 (Self::Plaintext(a), Self::Plaintext(b)) => a.is_equal(b),
71 (Self::Future(a), Self::Future(b)) => a.is_equal(b),
72 (Self::DynamicFuture(a), Self::DynamicFuture(b)) => a.is_equal(b),
73 (Self::Plaintext(..), _) | (Self::Future(..), _) | (Self::DynamicFuture(..), _) => Boolean::constant(false),
74 }
75 }
76
77 fn is_not_equal(&self, other: &Self) -> Self::Output {
79 match (self, other) {
80 (Self::Plaintext(a), Self::Plaintext(b)) => a.is_not_equal(b),
81 (Self::Future(a), Self::Future(b)) => a.is_not_equal(b),
82 (Self::DynamicFuture(a), Self::DynamicFuture(b)) => a.is_not_equal(b),
83 (Self::Plaintext(..), _) | (Self::Future(..), _) | (Self::DynamicFuture(..), _) => Boolean::constant(true),
84 }
85 }
86}
87
88impl<A: Aleo> ToBits for Argument<A> {
89 type Boolean = Boolean<A>;
90
91 #[inline]
93 fn write_bits_le(&self, vec: &mut Vec<Boolean<A>>) {
94 match self {
95 Self::Plaintext(plaintext) => {
96 vec.push(Boolean::constant(false));
97 plaintext.write_bits_le(vec);
98 }
99 Self::Future(future) => {
100 vec.push(Boolean::constant(true));
101 future.write_bits_le(vec);
102 }
103 Self::DynamicFuture(dynamic_future) => {
104 vec.push(Boolean::constant(true));
105 vec.extend(std::iter::repeat_n(Boolean::constant(false), 12));
112 dynamic_future.write_bits_le(vec);
113 }
114 }
115 }
116
117 #[inline]
119 fn write_bits_be(&self, vec: &mut Vec<Boolean<A>>) {
120 match self {
121 Self::Plaintext(plaintext) => {
122 vec.push(Boolean::constant(false));
123 plaintext.write_bits_be(vec);
124 }
125 Self::Future(future) => {
126 vec.push(Boolean::constant(true));
127 future.write_bits_be(vec);
128 }
129 Self::DynamicFuture(dynamic_future) => {
130 vec.push(Boolean::constant(true));
131 vec.extend(std::iter::repeat_n(Boolean::constant(false), 12));
138 dynamic_future.write_bits_be(vec);
139 }
140 }
141 }
142}