snarkvm_console_program/data/future/
argument.rsuse super::*;
#[derive(Clone)]
pub enum Argument<N: Network> {
Plaintext(Plaintext<N>),
Future(Future<N>),
}
impl<N: Network> Equal<Self> for Argument<N> {
type Output = Boolean<N>;
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::new(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::new(true),
}
}
}
impl<N: Network> FromBytes for Argument<N> {
fn read_le<R: Read>(mut reader: R) -> IoResult<Self>
where
Self: Sized,
{
let index = u8::read_le(&mut reader)?;
let argument = match index {
0 => Self::Plaintext(Plaintext::read_le(&mut reader)?),
1 => Self::Future(Future::read_le(&mut reader)?),
2.. => return Err(error(format!("Failed to decode future argument {index}"))),
};
Ok(argument)
}
}
impl<N: Network> ToBytes for Argument<N> {
fn write_le<W: Write>(&self, mut writer: W) -> IoResult<()> {
match self {
Self::Plaintext(plaintext) => {
0u8.write_le(&mut writer)?;
plaintext.write_le(&mut writer)
}
Self::Future(future) => {
1u8.write_le(&mut writer)?;
future.write_le(&mut writer)
}
}
}
}
impl<N: Network> ToBits for Argument<N> {
#[inline]
fn write_bits_le(&self, vec: &mut Vec<bool>) {
match self {
Self::Plaintext(plaintext) => {
vec.push(false);
plaintext.write_bits_le(vec);
}
Self::Future(future) => {
vec.push(true);
future.write_bits_le(vec);
}
}
}
#[inline]
fn write_bits_be(&self, vec: &mut Vec<bool>) {
match self {
Self::Plaintext(plaintext) => {
vec.push(false);
plaintext.write_bits_be(vec);
}
Self::Future(future) => {
vec.push(true);
future.write_bits_be(vec);
}
}
}
}