pub trait Sub<Rhs = Self> {
type Output;
// Required method
fn sub(self, rhs: Rhs) -> Self::Output;
}Expand description
The subtraction operator -.
Note that Rhs is Self by default, but this is not mandatory. For
example, std::time::SystemTime implements Sub<Duration>, which permits
operations of the form SystemTime = SystemTime - Duration.
§Examples
§Subtractable points
use std::ops::Sub;
#[derive(Debug, Copy, Clone, PartialEq)]
struct Point {
x: i32,
y: i32,
}
impl Sub for Point {
type Output = Self;
fn sub(self, other: Self) -> Self::Output {
Self {
x: self.x - other.x,
y: self.y - other.y,
}
}
}
assert_eq!(Point { x: 3, y: 3 } - Point { x: 2, y: 3 },
Point { x: 1, y: 0 });§Implementing Sub with generics
Here is an example of the same Point struct implementing the Sub trait
using generics.
use std::ops::Sub;
#[derive(Debug, PartialEq)]
struct Point<T> {
x: T,
y: T,
}
// Notice that the implementation uses the associated type `Output`.
impl<T: Sub<Output = T>> Sub for Point<T> {
type Output = Self;
fn sub(self, other: Self) -> Self::Output {
Point {
x: self.x - other.x,
y: self.y - other.y,
}
}
}
assert_eq!(Point { x: 2, y: 3 } - Point { x: 1, y: 0 },
Point { x: 1, y: 3 });Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl Sub for ProjectivePoint
impl Sub for ProjectivePoint
type Output = ProjectivePoint
1.74.0 (const: unstable) · Source§impl Sub for Saturating<i128>
impl Sub for Saturating<i128>
type Output = Saturating<i128>
1.74.0 (const: unstable) · Source§impl Sub for Saturating<isize>
impl Sub for Saturating<isize>
type Output = Saturating<isize>
1.74.0 (const: unstable) · Source§impl Sub for Saturating<u128>
impl Sub for Saturating<u128>
type Output = Saturating<u128>
1.74.0 (const: unstable) · Source§impl Sub for Saturating<usize>
impl Sub for Saturating<usize>
type Output = Saturating<usize>
Source§impl Sub<&AffinePoint> for &ProjectivePoint
impl Sub<&AffinePoint> for &ProjectivePoint
type Output = ProjectivePoint
Source§impl Sub<&AffinePoint> for ProjectivePoint
impl Sub<&AffinePoint> for ProjectivePoint
type Output = ProjectivePoint
Source§impl Sub<&ProjectivePoint> for &ProjectivePoint
impl Sub<&ProjectivePoint> for &ProjectivePoint
type Output = ProjectivePoint
Source§impl Sub<&ProjectivePoint> for ProjectivePoint
impl Sub<&ProjectivePoint> for ProjectivePoint
type Output = ProjectivePoint
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i8>> for &Saturating<i8>
impl Sub<&Saturating<i8>> for &Saturating<i8>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i8>> for Saturating<i8>
impl Sub<&Saturating<i8>> for Saturating<i8>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i16>> for &Saturating<i16>
impl Sub<&Saturating<i16>> for &Saturating<i16>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i16>> for Saturating<i16>
impl Sub<&Saturating<i16>> for Saturating<i16>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i32>> for &Saturating<i32>
impl Sub<&Saturating<i32>> for &Saturating<i32>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i32>> for Saturating<i32>
impl Sub<&Saturating<i32>> for Saturating<i32>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i64>> for &Saturating<i64>
impl Sub<&Saturating<i64>> for &Saturating<i64>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i64>> for Saturating<i64>
impl Sub<&Saturating<i64>> for Saturating<i64>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i128>> for &Saturating<i128>
impl Sub<&Saturating<i128>> for &Saturating<i128>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i128>> for Saturating<i128>
impl Sub<&Saturating<i128>> for Saturating<i128>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<isize>> for &Saturating<isize>
impl Sub<&Saturating<isize>> for &Saturating<isize>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<isize>> for Saturating<isize>
impl Sub<&Saturating<isize>> for Saturating<isize>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u8>> for &Saturating<u8>
impl Sub<&Saturating<u8>> for &Saturating<u8>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u8>> for Saturating<u8>
impl Sub<&Saturating<u8>> for Saturating<u8>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u16>> for &Saturating<u16>
impl Sub<&Saturating<u16>> for &Saturating<u16>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u16>> for Saturating<u16>
impl Sub<&Saturating<u16>> for Saturating<u16>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u32>> for &Saturating<u32>
impl Sub<&Saturating<u32>> for &Saturating<u32>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u32>> for Saturating<u32>
impl Sub<&Saturating<u32>> for Saturating<u32>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u64>> for &Saturating<u64>
impl Sub<&Saturating<u64>> for &Saturating<u64>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u64>> for Saturating<u64>
impl Sub<&Saturating<u64>> for Saturating<u64>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u128>> for &Saturating<u128>
impl Sub<&Saturating<u128>> for &Saturating<u128>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u128>> for Saturating<u128>
impl Sub<&Saturating<u128>> for Saturating<u128>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<usize>> for &Saturating<usize>
impl Sub<&Saturating<usize>> for &Saturating<usize>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<usize>> for Saturating<usize>
impl Sub<&Saturating<usize>> for Saturating<usize>
1.14.0 (const: unstable) · Source§impl Sub<&Wrapping<i128>> for &core::num::wrapping::Wrapping<i128>
impl Sub<&Wrapping<i128>> for &core::num::wrapping::Wrapping<i128>
1.14.0 (const: unstable) · Source§impl Sub<&Wrapping<isize>> for &core::num::wrapping::Wrapping<isize>
impl Sub<&Wrapping<isize>> for &core::num::wrapping::Wrapping<isize>
1.14.0 (const: unstable) · Source§impl Sub<&Wrapping<isize>> for core::num::wrapping::Wrapping<isize>
impl Sub<&Wrapping<isize>> for core::num::wrapping::Wrapping<isize>
1.14.0 (const: unstable) · Source§impl Sub<&Wrapping<u128>> for &core::num::wrapping::Wrapping<u128>
impl Sub<&Wrapping<u128>> for &core::num::wrapping::Wrapping<u128>
1.14.0 (const: unstable) · Source§impl Sub<&Wrapping<usize>> for &core::num::wrapping::Wrapping<usize>
impl Sub<&Wrapping<usize>> for &core::num::wrapping::Wrapping<usize>
1.14.0 (const: unstable) · Source§impl Sub<&Wrapping<usize>> for core::num::wrapping::Wrapping<usize>
impl Sub<&Wrapping<usize>> for core::num::wrapping::Wrapping<usize>
Source§impl Sub<AffinePoint> for ProjectivePoint
impl Sub<AffinePoint> for ProjectivePoint
type Output = ProjectivePoint
1.8.0 · Source§impl Sub<Duration> for SystemTime
impl Sub<Duration> for SystemTime
type Output = SystemTime
1.74.0 (const: unstable) · Source§impl Sub<Saturating<i8>> for &Saturating<i8>
impl Sub<Saturating<i8>> for &Saturating<i8>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<i16>> for &Saturating<i16>
impl Sub<Saturating<i16>> for &Saturating<i16>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<i32>> for &Saturating<i32>
impl Sub<Saturating<i32>> for &Saturating<i32>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<i64>> for &Saturating<i64>
impl Sub<Saturating<i64>> for &Saturating<i64>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<i128>> for &Saturating<i128>
impl Sub<Saturating<i128>> for &Saturating<i128>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<isize>> for &Saturating<isize>
impl Sub<Saturating<isize>> for &Saturating<isize>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<u8>> for &Saturating<u8>
impl Sub<Saturating<u8>> for &Saturating<u8>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<u16>> for &Saturating<u16>
impl Sub<Saturating<u16>> for &Saturating<u16>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<u32>> for &Saturating<u32>
impl Sub<Saturating<u32>> for &Saturating<u32>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<u64>> for &Saturating<u64>
impl Sub<Saturating<u64>> for &Saturating<u64>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<u128>> for &Saturating<u128>
impl Sub<Saturating<u128>> for &Saturating<u128>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<usize>> for &Saturating<usize>
impl Sub<Saturating<usize>> for &Saturating<usize>
1.14.0 (const: unstable) · Source§impl Sub<Wrapping<isize>> for &core::num::wrapping::Wrapping<isize>
impl Sub<Wrapping<isize>> for &core::num::wrapping::Wrapping<isize>
1.14.0 (const: unstable) · Source§impl Sub<Wrapping<usize>> for &core::num::wrapping::Wrapping<usize>
impl Sub<Wrapping<usize>> for &core::num::wrapping::Wrapping<usize>
Source§impl<'a, F> Sub<&'a DensePolynomial<F>> for &DensePolynomial<F>where
F: Field,
impl<'a, F> Sub<&'a DensePolynomial<F>> for &DensePolynomial<F>where
F: Field,
type Output = DensePolynomial<F>
Source§impl<'a, F> Sub<&'a Evaluations<F>> for &Evaluations<F>where
F: PrimeField,
impl<'a, F> Sub<&'a Evaluations<F>> for &Evaluations<F>where
F: PrimeField,
type Output = Evaluations<F>
Source§impl<'a, F> Sub<&'a LinearCombination<F>> for LinearCombination<F>where
F: Field,
impl<'a, F> Sub<&'a LinearCombination<F>> for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<'a, F> Sub<&'a SparsePolynomial<F>> for DensePolynomial<F>where
F: Field,
impl<'a, F> Sub<&'a SparsePolynomial<F>> for DensePolynomial<F>where
F: Field,
type Output = DensePolynomial<F>
Source§impl<'a, F> Sub<(F, &'a LinearCombination<F>)> for LinearCombination<F>where
F: Field,
impl<'a, F> Sub<(F, &'a LinearCombination<F>)> for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<'a, P> Sub<&'a Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
impl<'a, P> Sub<&'a Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
type Output = Projective<P>
Source§impl<'a, P> Sub<&'a Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
impl<'a, P> Sub<&'a Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
type Output = Projective<P>
Source§impl<'a, P> Sub<&'a mut Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
impl<'a, P> Sub<&'a mut Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
type Output = Projective<P>
Source§impl<'a, P> Sub<&'a mut Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
impl<'a, P> Sub<&'a mut Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
type Output = Projective<P>
Source§impl<C> Sub for ScalarValue<C>where
C: Curve,
impl<C> Sub for ScalarValue<C>where
C: Curve,
type Output = ScalarValue<C>
Source§impl<C> Sub<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
impl<C> Sub<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
type Output = ScalarValue<C>
Source§impl<E, I> Sub for Integer<E, I>where
E: Environment,
I: IntegerType,
impl<E, I> Sub for Integer<E, I>where
E: Environment,
I: IntegerType,
Source§impl<E, I> Sub<&Integer<E, I>> for Integer<E, I>where
E: Environment,
I: IntegerType,
impl<E, I> Sub<&Integer<E, I>> for Integer<E, I>where
E: Environment,
I: IntegerType,
Source§impl<E> Sub for snarkvm_console_program::Scalar<E>where
E: Environment,
impl<E> Sub for snarkvm_console_program::Scalar<E>where
E: Environment,
Source§impl<F> Sub for LinearCombination<F>where
F: Field,
impl<F> Sub for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Sub<&LinearCombination<F>> for &LinearCombination<F>where
F: Field,
impl<F> Sub<&LinearCombination<F>> for &LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Sub<(F, &LinearCombination<F>)> for &LinearCombination<F>where
F: Field,
impl<F> Sub<(F, &LinearCombination<F>)> for &LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Sub<(F, LinearCombination<F>)> for &LinearCombination<F>where
F: Field,
impl<F> Sub<(F, LinearCombination<F>)> for &LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Sub<(F, LinearCombination<F>)> for LinearCombination<F>where
F: Field,
impl<F> Sub<(F, LinearCombination<F>)> for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Sub<(F, Variable)> for LinearCombination<F>where
F: Field,
impl<F> Sub<(F, Variable)> for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Sub<LinearCombination<F>> for &LinearCombination<F>where
F: Field,
impl<F> Sub<LinearCombination<F>> for &LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Sub<Variable> for LinearCombination<F>where
F: Field,
impl<F> Sub<Variable> for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<MOD, const LIMBS: usize> Sub for ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
impl<MOD, const LIMBS: usize> Sub for ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
type Output = ConstMontyForm<MOD, LIMBS>
Source§impl<MOD, const LIMBS: usize> Sub<&ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
impl<MOD, const LIMBS: usize> Sub<&ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
type Output = ConstMontyForm<MOD, LIMBS>
Source§impl<MOD, const LIMBS: usize> Sub<&ConstMontyForm<MOD, LIMBS>> for ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
impl<MOD, const LIMBS: usize> Sub<&ConstMontyForm<MOD, LIMBS>> for ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
type Output = ConstMontyForm<MOD, LIMBS>
Source§impl<MOD, const LIMBS: usize> Sub<ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
impl<MOD, const LIMBS: usize> Sub<ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
type Output = ConstMontyForm<MOD, LIMBS>
Source§impl<P> Sub for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
impl<P> Sub for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
type Output = Projective<P>
Source§impl<P> Sub for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
impl<P> Sub for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
type Output = Projective<P>
Source§impl<P> Sub<&&Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
impl<P> Sub<&&Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
type Output = Projective<P>
Source§impl<P> Sub<&&Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
impl<P> Sub<&&Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
type Output = Projective<P>
Source§impl<T> Sub for crypto_bigint::wrapping::Wrapping<T>where
T: WrappingSub,
impl<T> Sub for crypto_bigint::wrapping::Wrapping<T>where
T: WrappingSub,
Source§impl<Ul, Bl, Ur> Sub<Ur> for UInt<Ul, Bl>
Subtracting unsigned integers. We just do our PrivateSub and then Trim the output.
impl<Ul, Bl, Ur> Sub<Ur> for UInt<Ul, Bl>
Subtracting unsigned integers. We just do our PrivateSub and then Trim the output.