snarkvm_console_program/data/future/
argument.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::*;
17
18/// An argument passed into a future.
19#[derive(Clone)]
20pub enum Argument<N: Network> {
21    /// A plaintext value.
22    Plaintext(Plaintext<N>),
23    /// A future.
24    Future(Future<N>),
25}
26
27impl<N: Network> Equal<Self> for Argument<N> {
28    type Output = Boolean<N>;
29
30    /// Returns `true` if `self` and `other` are equal.
31    fn is_equal(&self, other: &Self) -> Self::Output {
32        match (self, other) {
33            (Self::Plaintext(plaintext_a), Self::Plaintext(plaintext_b)) => plaintext_a.is_equal(plaintext_b),
34            (Self::Future(future_a), Self::Future(future_b)) => future_a.is_equal(future_b),
35            (Self::Plaintext(..), _) | (Self::Future(..), _) => Boolean::new(false),
36        }
37    }
38
39    /// Returns `true` if `self` and `other` are *not* equal.
40    fn is_not_equal(&self, other: &Self) -> Self::Output {
41        match (self, other) {
42            (Self::Plaintext(plaintext_a), Self::Plaintext(plaintext_b)) => plaintext_a.is_not_equal(plaintext_b),
43            (Self::Future(future_a), Self::Future(future_b)) => future_a.is_not_equal(future_b),
44            (Self::Plaintext(..), _) | (Self::Future(..), _) => Boolean::new(true),
45        }
46    }
47}
48
49impl<N: Network> ToBits for Argument<N> {
50    /// Returns the argument as a list of **little-endian** bits.
51    #[inline]
52    fn write_bits_le(&self, vec: &mut Vec<bool>) {
53        match self {
54            Self::Plaintext(plaintext) => {
55                vec.push(false);
56                plaintext.write_bits_le(vec);
57            }
58            Self::Future(future) => {
59                vec.push(true);
60                future.write_bits_le(vec);
61            }
62        }
63    }
64
65    /// Returns the argument as a list of **big-endian** bits.
66    #[inline]
67    fn write_bits_be(&self, vec: &mut Vec<bool>) {
68        match self {
69            Self::Plaintext(plaintext) => {
70                vec.push(false);
71                plaintext.write_bits_be(vec);
72            }
73            Self::Future(future) => {
74                vec.push(true);
75                future.write_bits_be(vec);
76            }
77        }
78    }
79}