use snarkvm_fields::{Field, PrimeField};
use snarkvm_r1cs::ConstraintSystem;
use crate::{errors::UnsignedIntegerError, integers::uint::*};
pub trait Sub<F: Field, Rhs = Self>
where
Self: std::marker::Sized,
{
type ErrorType;
fn sub<CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, Self::ErrorType>;
}
macro_rules! sub_int_impl {
($($gadget:ident),*) => ($(
impl<F: PrimeField> Sub<F> for $gadget {
type ErrorType = UnsignedIntegerError;
fn sub<CS: ConstraintSystem<F>>(
&self,
mut cs: CS,
other: &Self,
) -> Result<Self, Self::ErrorType> {
Self::addmany(&mut cs.ns(|| "add_not"), &[self.clone(), other.negate()]).map_err(|e| e.into())
}
}
)*)
}
sub_int_impl!(UInt8, UInt16, UInt32, UInt64, UInt128);