Trait scale_info::prelude::ops::Sub

1.0.0 · source · []
pub trait Sub<Rhs = Self> {
    type Output;
    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 });

Associated Types

The resulting type after applying the - operator.

Required methods

Performs the - operation.

Example
assert_eq!(12 - 1, 11);

Implementations on Foreign Types

Implementors

impl<Tz: TimeZone> Sub<FixedOffset> for DateTime<Tz>

impl<Tz: TimeZone> Sub<Duration> for Date<Tz>

impl<Tz: TimeZone> Sub<Date<Tz>> for Date<Tz>

impl<Tz: TimeZone> Sub<Duration> for DateTime<Tz>

impl<Tz: TimeZone> Sub<DateTime<Tz>> for DateTime<Tz>

impl<'a, 'b> Sub<&'b Scalar> for &'a Scalar

impl<'b> Sub<&'b Scalar> for Scalar

impl<'a> Sub<Scalar> for &'a Scalar

impl Sub<Scalar> for Scalar

impl<'a, 'b> Sub<&'b EdwardsPoint> for &'a EdwardsPoint

impl<'b> Sub<&'b EdwardsPoint> for EdwardsPoint

impl<'a> Sub<EdwardsPoint> for &'a EdwardsPoint

impl<'a, 'b> Sub<&'b RistrettoPoint> for &'a RistrettoPoint

impl<T, S> Sub<&'_ HashSet<T, S, Global>> for &HashSet<T, S> where
    T: Eq + Hash + Clone,
    S: BuildHasher + Default

impl<T: Into<Self>> Sub<T> for Bytes

impl<T: Into<Self>> Sub<T> for Words

impl<T: Into<Self>> Sub<T> for Pages

impl<T: Into<Self>> Sub<T> for Words

impl<T: Into<Self>> Sub<T> for Pages

impl Sub<usize> for Dynamic

impl<'b, T, R1, C1, R2, C2, SA, SB> Sub<&'b Matrix<T, R2, C2, SB>> for Matrix<T, R1, C1, SA> where
    R1: Dim,
    C1: Dim,
    R2: Dim,
    C2: Dim,
    T: Scalar + ClosedSub,
    SA: Storage<T, R1, C1>,
    SB: Storage<T, R2, C2>,
    DefaultAllocator: SameShapeAllocator<T, R1, C1, R2, C2>,
    ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>, 

impl<'a, T, R1, C1, R2, C2, SA, SB> Sub<Matrix<T, R2, C2, SB>> for &'a Matrix<T, R1, C1, SA> where
    R1: Dim,
    C1: Dim,
    R2: Dim,
    C2: Dim,
    T: Scalar + ClosedSub,
    SA: Storage<T, R1, C1>,
    SB: Storage<T, R2, C2>,
    DefaultAllocator: SameShapeAllocator<T, R2, C2, R1, C1>,
    ShapeConstraint: SameNumberOfRows<R2, R1> + SameNumberOfColumns<C2, C1>, 

impl<T, R1, C1, R2, C2, SA, SB> Sub<Matrix<T, R2, C2, SB>> for Matrix<T, R1, C1, SA> where
    R1: Dim,
    C1: Dim,
    R2: Dim,
    C2: Dim,
    T: Scalar + ClosedSub,
    SA: Storage<T, R1, C1>,
    SB: Storage<T, R2, C2>,
    DefaultAllocator: SameShapeAllocator<T, R1, C1, R2, C2>,
    ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>, 

impl<'a, 'b, T, R1, C1, R2, C2, SA, SB> Sub<&'b Matrix<T, R2, C2, SB>> for &'a Matrix<T, R1, C1, SA> where
    R1: Dim,
    C1: Dim,
    R2: Dim,
    C2: Dim,
    T: Scalar + ClosedSub,
    SA: Storage<T, R1, C1>,
    SB: Storage<T, R2, C2>,
    DefaultAllocator: SameShapeAllocator<T, R1, C1, R2, C2>,
    ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>, 

impl<'a, 'b, T, const D: usize> Sub<&'b Point<T, D>> for &'a Point<T, D> where
    T: Scalar + ClosedSub,
    ShapeConstraint: SameNumberOfRows<Const<D>, Const<D>, Representative = Const<D>> + SameNumberOfColumns<U1, U1, Representative = U1>, 

impl<'a, T, const D: usize> Sub<Point<T, D>> for &'a Point<T, D> where
    T: Scalar + ClosedSub,
    ShapeConstraint: SameNumberOfRows<Const<D>, Const<D>, Representative = Const<D>> + SameNumberOfColumns<U1, U1, Representative = U1>, 

impl<'b, T, const D: usize> Sub<&'b Point<T, D>> for Point<T, D> where
    T: Scalar + ClosedSub,
    ShapeConstraint: SameNumberOfRows<Const<D>, Const<D>, Representative = Const<D>> + SameNumberOfColumns<U1, U1, Representative = U1>, 

impl<T, const D: usize> Sub<Point<T, D>> for Point<T, D> where
    T: Scalar + ClosedSub,
    ShapeConstraint: SameNumberOfRows<Const<D>, Const<D>, Representative = Const<D>> + SameNumberOfColumns<U1, U1, Representative = U1>, 

impl<'a, 'b, T, D2, SB, const D1: usize> Sub<&'b Matrix<T, D2, Const<1_usize>, SB>> for &'a Point<T, D1> where
    T: Scalar + ClosedSub,
    ShapeConstraint: SameNumberOfRows<Const<D1>, D2, Representative = Const<D1>> + SameNumberOfColumns<U1, U1, Representative = U1>,
    D2: Dim,
    SB: Storage<T, D2>, 

impl<'a, T, D2, SB, const D1: usize> Sub<Matrix<T, D2, Const<1_usize>, SB>> for &'a Point<T, D1> where
    T: Scalar + ClosedSub,
    ShapeConstraint: SameNumberOfRows<Const<D1>, D2, Representative = Const<D1>> + SameNumberOfColumns<U1, U1, Representative = U1>,
    D2: Dim,
    SB: Storage<T, D2>, 

impl<'b, T, D2, SB, const D1: usize> Sub<&'b Matrix<T, D2, Const<1_usize>, SB>> for Point<T, D1> where
    T: Scalar + ClosedSub,
    ShapeConstraint: SameNumberOfRows<Const<D1>, D2, Representative = Const<D1>> + SameNumberOfColumns<U1, U1, Representative = U1>,
    D2: Dim,
    SB: Storage<T, D2>, 

impl<T, D2, SB, const D1: usize> Sub<Matrix<T, D2, Const<1_usize>, SB>> for Point<T, D1> where
    T: Scalar + ClosedSub,
    ShapeConstraint: SameNumberOfRows<Const<D1>, D2, Representative = Const<D1>> + SameNumberOfColumns<U1, U1, Representative = U1>,
    D2: Dim,
    SB: Storage<T, D2>, 

impl<'a, 'b, T: SimdRealField> Sub<&'b Quaternion<T>> for &'a Quaternion<T> where
    T::Element: SimdRealField

impl<'a, T: SimdRealField> Sub<Quaternion<T>> for &'a Quaternion<T> where
    T::Element: SimdRealField

impl<'b, T: SimdRealField> Sub<&'b Quaternion<T>> for Quaternion<T> where
    T::Element: SimdRealField

impl<T: SimdRealField> Sub<Quaternion<T>> for Quaternion<T> where
    T::Element: SimdRealField

impl<'a, 'b, T: SimdRealField> Sub<&'b DualQuaternion<T>> for &'a DualQuaternion<T> where
    T::Element: SimdRealField

impl<'a, T: SimdRealField> Sub<DualQuaternion<T>> for &'a DualQuaternion<T> where
    T::Element: SimdRealField

impl<'b, T: SimdRealField> Sub<&'b DualQuaternion<T>> for DualQuaternion<T> where
    T::Element: SimdRealField

impl<T: SimdRealField> Sub<DualQuaternion<T>> for DualQuaternion<T> where
    T::Element: SimdRealField

impl<'a, 'b, T: Clone + Num> Sub<&'b Complex<T>> for &'a Complex<T>

impl<'a, T: Clone + Num> Sub<Complex<T>> for &'a Complex<T>

impl<'a, T: Clone + Num> Sub<&'a Complex<T>> for Complex<T>

impl<T: Clone + Num> Sub<Complex<T>> for Complex<T>

impl<T: Clone + Num> Sub<T> for Complex<T>

impl<'a, T: Clone + Num> Sub<&'a T> for Complex<T>

impl<'a, T: Clone + Num> Sub<T> for &'a Complex<T>

impl<'a, 'b, T: Clone + Num> Sub<&'a T> for &'b Complex<T>

impl<'a> Sub<&'a Complex<usize>> for usize

impl<'a> Sub<Complex<usize>> for &'a usize

impl<'a, 'b> Sub<&'a Complex<usize>> for &'b usize

impl<'a> Sub<&'a Complex<u8>> for u8

impl<'a> Sub<Complex<u8>> for &'a u8

impl<'a, 'b> Sub<&'a Complex<u8>> for &'b u8

impl<'a> Sub<&'a Complex<u16>> for u16

impl<'a> Sub<Complex<u16>> for &'a u16

impl<'a, 'b> Sub<&'a Complex<u16>> for &'b u16

impl<'a> Sub<&'a Complex<u32>> for u32

impl<'a> Sub<Complex<u32>> for &'a u32

impl<'a, 'b> Sub<&'a Complex<u32>> for &'b u32

impl<'a> Sub<&'a Complex<u64>> for u64

impl<'a> Sub<Complex<u64>> for &'a u64

impl<'a, 'b> Sub<&'a Complex<u64>> for &'b u64

impl<'a> Sub<&'a Complex<u128>> for u128

impl<'a> Sub<Complex<u128>> for &'a u128

impl<'a, 'b> Sub<&'a Complex<u128>> for &'b u128

impl<'a> Sub<&'a Complex<isize>> for isize

impl<'a> Sub<Complex<isize>> for &'a isize

impl<'a, 'b> Sub<&'a Complex<isize>> for &'b isize

impl<'a> Sub<&'a Complex<i8>> for i8

impl<'a> Sub<Complex<i8>> for &'a i8

impl<'a, 'b> Sub<&'a Complex<i8>> for &'b i8

impl<'a> Sub<&'a Complex<i16>> for i16

impl<'a> Sub<Complex<i16>> for &'a i16

impl<'a, 'b> Sub<&'a Complex<i16>> for &'b i16

impl<'a> Sub<&'a Complex<i32>> for i32

impl<'a> Sub<Complex<i32>> for &'a i32

impl<'a, 'b> Sub<&'a Complex<i32>> for &'b i32

impl<'a> Sub<&'a Complex<i64>> for i64

impl<'a> Sub<Complex<i64>> for &'a i64

impl<'a, 'b> Sub<&'a Complex<i64>> for &'b i64

impl<'a> Sub<&'a Complex<i128>> for i128

impl<'a> Sub<Complex<i128>> for &'a i128

impl<'a, 'b> Sub<&'a Complex<i128>> for &'b i128

impl<'a> Sub<&'a Complex<f32>> for f32

impl<'a> Sub<Complex<f32>> for &'a f32

impl<'a, 'b> Sub<&'a Complex<f32>> for &'b f32

impl<'a> Sub<&'a Complex<f64>> for f64

impl<'a> Sub<Complex<f64>> for &'a f64

impl<'a, 'b> Sub<&'a Complex<f64>> for &'b f64

impl Sub<Complex<usize>> for usize

impl Sub<Complex<u8>> for u8

impl Sub<Complex<u16>> for u16

impl Sub<Complex<u32>> for u32

impl Sub<Complex<u64>> for u64

impl Sub<Complex<u128>> for u128

impl Sub<Complex<isize>> for isize

impl Sub<Complex<i8>> for i8

impl Sub<Complex<i16>> for i16

impl Sub<Complex<i32>> for i32

impl Sub<Complex<i64>> for i64

impl Sub<Complex<i128>> for i128

impl Sub<Complex<f32>> for f32

impl Sub<Complex<f64>> for f64

impl<'a, 'b, T: Clone + Integer> Sub<&'b Ratio<T>> for &'a Ratio<T>

impl<'a, 'b, T: Clone + Integer> Sub<&'b T> for &'a Ratio<T>

impl<'a, T> Sub<Ratio<T>> for &'a Ratio<T> where
    T: Clone + Integer

impl<'a, T> Sub<T> for &'a Ratio<T> where
    T: Clone + Integer

impl<'a, T> Sub<&'a Ratio<T>> for Ratio<T> where
    T: Clone + Integer

impl<'a, T> Sub<&'a T> for Ratio<T> where
    T: Clone + Integer

impl<T: Clone + Integer> Sub<Ratio<T>> for Ratio<T>

impl<T: Clone + Integer> Sub<T> for Ratio<T>

impl<T> Sub<T> for U128 where
    T: Into<U128>, 

impl<'a, T> Sub<T> for &'a U128 where
    T: Into<U128>, 

impl<T> Sub<T> for U256 where
    T: Into<U256>, 

impl<'a, T> Sub<T> for &'a U256 where
    T: Into<U256>, 

impl<T> Sub<T> for U512 where
    T: Into<U512>, 

impl<'a, T> Sub<T> for &'a U512 where
    T: Into<U512>, 

impl Sub<BigUint> for BigUint

impl Sub<Percent> for Percent

impl Sub<PerU16> for PerU16

impl Sub<Permill> for Permill

impl Sub<Perbill> for Perbill

impl Sub<Z0> for Z0

impl<U: Unsigned + NonZero> Sub<PInt<U>> for Z0

impl<U: Unsigned + NonZero> Sub<NInt<U>> for Z0

impl<U: Unsigned + NonZero> Sub<Z0> for PInt<U>

impl<U: Unsigned + NonZero> Sub<Z0> for NInt<U>

impl<Ul: Unsigned + NonZero, Ur: Unsigned + NonZero> Sub<NInt<Ur>> for PInt<Ul> where
    Ul: Add<Ur>,
    <Ul as Add<Ur>>::Output: Unsigned + NonZero

impl<Ul: Unsigned + NonZero, Ur: Unsigned + NonZero> Sub<PInt<Ur>> for NInt<Ul> where
    Ul: Add<Ur>,
    <Ul as Add<Ur>>::Output: Unsigned + NonZero

impl<Ul: Unsigned + NonZero, Ur: Unsigned + NonZero> Sub<PInt<Ur>> for PInt<Ul> where
    Ul: Cmp<Ur> + PrivateIntegerAdd<<Ul as Cmp<Ur>>::Output, Ur>, 

impl<Ul: Unsigned + NonZero, Ur: Unsigned + NonZero> Sub<NInt<Ur>> for NInt<Ul> where
    Ur: Cmp<Ul> + PrivateIntegerAdd<<Ur as Cmp<Ul>>::Output, Ul>, 

impl Sub<B0> for UTerm

impl<U: Unsigned, B: Bit> Sub<B0> for UInt<U, B>

impl<U: Unsigned, B: Bit> Sub<B1> for UInt<UInt<U, B>, B1>

impl Sub<B1> for UInt<UTerm, B1>

impl<U: Unsigned> Sub<B1> for UInt<U, B0> where
    U: Sub<B1>,
    Sub1<U>: Unsigned

impl Sub<UTerm> for UTerm

impl<Ul: Unsigned, Bl: Bit, Ur: Unsigned> Sub<Ur> for UInt<Ul, Bl> where
    UInt<Ul, Bl>: PrivateSub<Ur>,
    PrivateSubOut<UInt<Ul, Bl>, Ur>: Trim, 

impl Sub<ATerm> for ATerm

impl<Vl, Al, Vr, Ar> Sub<TArr<Vr, Ar>> for TArr<Vl, Al> where
    Vl: Sub<Vr>,
    Al: Sub<Ar>, 

impl<T: Into<F32>> Sub<T> for F32

impl<T: Into<F64>> Sub<T> for F64