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}
26
27impl<A: Aleo> Inject for Argument<A> {
28 type Primitive = console::Argument<A::Network>;
29
30 fn new(mode: Mode, value: Self::Primitive) -> Self {
32 match value {
33 console::Argument::Plaintext(plaintext) => Self::Plaintext(Inject::new(mode, plaintext)),
34 console::Argument::Future(future) => Self::Future(Inject::new(mode, future)),
35 }
36 }
37}
38
39impl<A: Aleo> Eject for Argument<A> {
40 type Primitive = console::Argument<A::Network>;
41
42 fn eject_mode(&self) -> Mode {
44 match self {
45 Self::Plaintext(plaintext) => plaintext.eject_mode(),
46 Self::Future(future) => future.eject_mode(),
47 }
48 }
49
50 fn eject_value(&self) -> Self::Primitive {
52 match self {
53 Self::Plaintext(plaintext) => Self::Primitive::Plaintext(plaintext.eject_value()),
54 Self::Future(future) => Self::Primitive::Future(future.eject_value()),
55 }
56 }
57}
58
59impl<A: Aleo> Equal<Self> for Argument<A> {
60 type Output = Boolean<A>;
61
62 fn is_equal(&self, other: &Self) -> Self::Output {
64 match (self, other) {
65 (Self::Plaintext(plaintext_a), Self::Plaintext(plaintext_b)) => plaintext_a.is_equal(plaintext_b),
66 (Self::Future(future_a), Self::Future(future_b)) => future_a.is_equal(future_b),
67 (Self::Plaintext(..), _) | (Self::Future(..), _) => Boolean::constant(false),
68 }
69 }
70
71 fn is_not_equal(&self, other: &Self) -> Self::Output {
73 match (self, other) {
74 (Self::Plaintext(plaintext_a), Self::Plaintext(plaintext_b)) => plaintext_a.is_not_equal(plaintext_b),
75 (Self::Future(future_a), Self::Future(future_b)) => future_a.is_not_equal(future_b),
76 (Self::Plaintext(..), _) | (Self::Future(..), _) => Boolean::constant(true),
77 }
78 }
79}
80
81impl<A: Aleo> ToBits for Argument<A> {
82 type Boolean = Boolean<A>;
83
84 #[inline]
86 fn write_bits_le(&self, vec: &mut Vec<Boolean<A>>) {
87 match self {
88 Self::Plaintext(plaintext) => {
89 vec.push(Boolean::constant(false));
90 plaintext.write_bits_le(vec);
91 }
92 Self::Future(future) => {
93 vec.push(Boolean::constant(true));
94 future.write_bits_le(vec);
95 }
96 }
97 }
98
99 #[inline]
101 fn write_bits_be(&self, vec: &mut Vec<Boolean<A>>) {
102 match self {
103 Self::Plaintext(plaintext) => {
104 vec.push(Boolean::constant(false));
105 plaintext.write_bits_be(vec);
106 }
107 Self::Future(future) => {
108 vec.push(Boolean::constant(true));
109 future.write_bits_be(vec);
110 }
111 }
112 }
113}