snarkvm_circuit_program/data/future/
argument.rsuse super::*;
#[derive(Clone)]
pub enum Argument<A: Aleo> {
Plaintext(Plaintext<A>),
Future(Future<A>),
}
impl<A: Aleo> Inject for Argument<A> {
type Primitive = console::Argument<A::Network>;
fn new(mode: Mode, value: Self::Primitive) -> Self {
match value {
console::Argument::Plaintext(plaintext) => Self::Plaintext(Inject::new(mode, plaintext)),
console::Argument::Future(future) => Self::Future(Inject::new(mode, future)),
}
}
}
impl<A: Aleo> Eject for Argument<A> {
type Primitive = console::Argument<A::Network>;
fn eject_mode(&self) -> Mode {
match self {
Self::Plaintext(plaintext) => plaintext.eject_mode(),
Self::Future(future) => future.eject_mode(),
}
}
fn eject_value(&self) -> Self::Primitive {
match self {
Self::Plaintext(plaintext) => Self::Primitive::Plaintext(plaintext.eject_value()),
Self::Future(future) => Self::Primitive::Future(future.eject_value()),
}
}
}
impl<A: Aleo> Equal<Self> for Argument<A> {
type Output = Boolean<A>;
fn is_equal(&self, other: &Self) -> Self::Output {
match (self, other) {
(Self::Plaintext(plaintext_a), Self::Plaintext(plaintext_b)) => plaintext_a.is_equal(plaintext_b),
(Self::Future(future_a), Self::Future(future_b)) => future_a.is_equal(future_b),
(Self::Plaintext(..), _) | (Self::Future(..), _) => Boolean::constant(false),
}
}
fn is_not_equal(&self, other: &Self) -> Self::Output {
match (self, other) {
(Self::Plaintext(plaintext_a), Self::Plaintext(plaintext_b)) => plaintext_a.is_not_equal(plaintext_b),
(Self::Future(future_a), Self::Future(future_b)) => future_a.is_not_equal(future_b),
(Self::Plaintext(..), _) | (Self::Future(..), _) => Boolean::constant(true),
}
}
}
impl<A: Aleo> ToBits for Argument<A> {
type Boolean = Boolean<A>;
#[inline]
fn write_bits_le(&self, vec: &mut Vec<Boolean<A>>) {
match self {
Self::Plaintext(plaintext) => {
vec.push(Boolean::constant(false));
plaintext.write_bits_le(vec);
}
Self::Future(future) => {
vec.push(Boolean::constant(true));
future.write_bits_le(vec);
}
}
}
#[inline]
fn write_bits_be(&self, vec: &mut Vec<Boolean<A>>) {
match self {
Self::Plaintext(plaintext) => {
vec.push(Boolean::constant(false));
plaintext.write_bits_be(vec);
}
Self::Future(future) => {
vec.push(Boolean::constant(true));
future.write_bits_be(vec);
}
}
}
}