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
§Sub
tractable 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§
Implementors§
1.74.0 · Source§impl Sub for Saturating<i8>
impl Sub for Saturating<i8>
type Output = Saturating<i8>
1.74.0 · Source§impl Sub for Saturating<i16>
impl Sub for Saturating<i16>
type Output = Saturating<i16>
1.74.0 · Source§impl Sub for Saturating<i32>
impl Sub for Saturating<i32>
type Output = Saturating<i32>
1.74.0 · Source§impl Sub for Saturating<i64>
impl Sub for Saturating<i64>
type Output = Saturating<i64>
1.74.0 · Source§impl Sub for Saturating<i128>
impl Sub for Saturating<i128>
type Output = Saturating<i128>
1.74.0 · Source§impl Sub for Saturating<isize>
impl Sub for Saturating<isize>
type Output = Saturating<isize>
1.74.0 · Source§impl Sub for Saturating<u8>
impl Sub for Saturating<u8>
type Output = Saturating<u8>
1.74.0 · Source§impl Sub for Saturating<u16>
impl Sub for Saturating<u16>
type Output = Saturating<u16>
1.74.0 · Source§impl Sub for Saturating<u32>
impl Sub for Saturating<u32>
type Output = Saturating<u32>
1.74.0 · Source§impl Sub for Saturating<u64>
impl Sub for Saturating<u64>
type Output = Saturating<u64>
1.74.0 · Source§impl Sub for Saturating<u128>
impl Sub for Saturating<u128>
type Output = Saturating<u128>
1.74.0 · Source§impl Sub for Saturating<usize>
impl Sub for Saturating<usize>
type Output = Saturating<usize>
Source§impl Sub for starknet_ff::FieldElement
impl Sub for starknet_ff::FieldElement
type Output = FieldElement
Source§impl Sub for ProjectivePoint
impl Sub for ProjectivePoint
type Output = ProjectivePoint
Source§impl Sub<&ExecutionResources> for &ExecutionResources
impl Sub<&ExecutionResources> for &ExecutionResources
type Output = ExecutionResources
1.74.0 · Source§impl Sub<&Saturating<i8>> for &Saturating<i8>
impl Sub<&Saturating<i8>> for &Saturating<i8>
1.74.0 · Source§impl Sub<&Saturating<i8>> for Saturating<i8>
impl Sub<&Saturating<i8>> for Saturating<i8>
1.74.0 · Source§impl Sub<&Saturating<i16>> for &Saturating<i16>
impl Sub<&Saturating<i16>> for &Saturating<i16>
1.74.0 · Source§impl Sub<&Saturating<i16>> for Saturating<i16>
impl Sub<&Saturating<i16>> for Saturating<i16>
1.74.0 · Source§impl Sub<&Saturating<i32>> for &Saturating<i32>
impl Sub<&Saturating<i32>> for &Saturating<i32>
1.74.0 · Source§impl Sub<&Saturating<i32>> for Saturating<i32>
impl Sub<&Saturating<i32>> for Saturating<i32>
1.74.0 · Source§impl Sub<&Saturating<i64>> for &Saturating<i64>
impl Sub<&Saturating<i64>> for &Saturating<i64>
1.74.0 · Source§impl Sub<&Saturating<i64>> for Saturating<i64>
impl Sub<&Saturating<i64>> for Saturating<i64>
1.74.0 · Source§impl Sub<&Saturating<i128>> for &Saturating<i128>
impl Sub<&Saturating<i128>> for &Saturating<i128>
1.74.0 · Source§impl Sub<&Saturating<i128>> for Saturating<i128>
impl Sub<&Saturating<i128>> for Saturating<i128>
1.74.0 · Source§impl Sub<&Saturating<isize>> for &Saturating<isize>
impl Sub<&Saturating<isize>> for &Saturating<isize>
1.74.0 · Source§impl Sub<&Saturating<isize>> for Saturating<isize>
impl Sub<&Saturating<isize>> for Saturating<isize>
1.74.0 · Source§impl Sub<&Saturating<u8>> for &Saturating<u8>
impl Sub<&Saturating<u8>> for &Saturating<u8>
1.74.0 · Source§impl Sub<&Saturating<u8>> for Saturating<u8>
impl Sub<&Saturating<u8>> for Saturating<u8>
1.74.0 · Source§impl Sub<&Saturating<u16>> for &Saturating<u16>
impl Sub<&Saturating<u16>> for &Saturating<u16>
1.74.0 · Source§impl Sub<&Saturating<u16>> for Saturating<u16>
impl Sub<&Saturating<u16>> for Saturating<u16>
1.74.0 · Source§impl Sub<&Saturating<u32>> for &Saturating<u32>
impl Sub<&Saturating<u32>> for &Saturating<u32>
1.74.0 · Source§impl Sub<&Saturating<u32>> for Saturating<u32>
impl Sub<&Saturating<u32>> for Saturating<u32>
1.74.0 · Source§impl Sub<&Saturating<u64>> for &Saturating<u64>
impl Sub<&Saturating<u64>> for &Saturating<u64>
1.74.0 · Source§impl Sub<&Saturating<u64>> for Saturating<u64>
impl Sub<&Saturating<u64>> for Saturating<u64>
1.74.0 · Source§impl Sub<&Saturating<u128>> for &Saturating<u128>
impl Sub<&Saturating<u128>> for &Saturating<u128>
1.74.0 · Source§impl Sub<&Saturating<u128>> for Saturating<u128>
impl Sub<&Saturating<u128>> for Saturating<u128>
1.74.0 · Source§impl Sub<&Saturating<usize>> for &Saturating<usize>
impl Sub<&Saturating<usize>> for &Saturating<usize>
1.74.0 · Source§impl Sub<&Saturating<usize>> for Saturating<usize>
impl Sub<&Saturating<usize>> for Saturating<usize>
Source§impl Sub<&AffinePoint> for &AffinePoint
impl Sub<&AffinePoint> for &AffinePoint
type Output = AffinePoint
Source§impl Sub<&ProjectivePoint> for &ProjectivePoint
impl Sub<&ProjectivePoint> 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 · Source§impl<'a> Sub<Saturating<i8>> for &'a Saturating<i8>
impl<'a> Sub<Saturating<i8>> for &'a Saturating<i8>
1.74.0 · Source§impl<'a> Sub<Saturating<i16>> for &'a Saturating<i16>
impl<'a> Sub<Saturating<i16>> for &'a Saturating<i16>
1.74.0 · Source§impl<'a> Sub<Saturating<i32>> for &'a Saturating<i32>
impl<'a> Sub<Saturating<i32>> for &'a Saturating<i32>
1.74.0 · Source§impl<'a> Sub<Saturating<i64>> for &'a Saturating<i64>
impl<'a> Sub<Saturating<i64>> for &'a Saturating<i64>
1.74.0 · Source§impl<'a> Sub<Saturating<i128>> for &'a Saturating<i128>
impl<'a> Sub<Saturating<i128>> for &'a Saturating<i128>
1.74.0 · Source§impl<'a> Sub<Saturating<isize>> for &'a Saturating<isize>
impl<'a> Sub<Saturating<isize>> for &'a Saturating<isize>
1.74.0 · Source§impl<'a> Sub<Saturating<u8>> for &'a Saturating<u8>
impl<'a> Sub<Saturating<u8>> for &'a Saturating<u8>
1.74.0 · Source§impl<'a> Sub<Saturating<u16>> for &'a Saturating<u16>
impl<'a> Sub<Saturating<u16>> for &'a Saturating<u16>
1.74.0 · Source§impl<'a> Sub<Saturating<u32>> for &'a Saturating<u32>
impl<'a> Sub<Saturating<u32>> for &'a Saturating<u32>
1.74.0 · Source§impl<'a> Sub<Saturating<u64>> for &'a Saturating<u64>
impl<'a> Sub<Saturating<u64>> for &'a Saturating<u64>
1.74.0 · Source§impl<'a> Sub<Saturating<u128>> for &'a Saturating<u128>
impl<'a> Sub<Saturating<u128>> for &'a Saturating<u128>
1.74.0 · Source§impl<'a> Sub<Saturating<usize>> for &'a Saturating<usize>
impl<'a> Sub<Saturating<usize>> for &'a Saturating<usize>
Source§impl<'a, 'b, P> Sub<&'a CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
impl<'a, 'b, P> Sub<&'a CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
Source§impl<'a, 'b, P> Sub<&'a QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
impl<'a, 'b, P> Sub<&'a QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
Source§impl<'a, 'b, P> Sub<&'a mut CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
impl<'a, 'b, P> Sub<&'a mut CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
Source§impl<'a, 'b, P> Sub<&'a mut QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
impl<'a, 'b, P> Sub<&'a mut QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
Source§impl<'a, P> Sub<&'a CubicExtField<P>> for CubicExtField<P>where
P: CubicExtConfig,
impl<'a, P> Sub<&'a CubicExtField<P>> for CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
Source§impl<'a, P> Sub<&'a QuadExtField<P>> for QuadExtField<P>where
P: QuadExtConfig,
impl<'a, P> Sub<&'a QuadExtField<P>> for QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
Source§impl<'a, P> Sub<&'a mut CubicExtField<P>> for CubicExtField<P>where
P: CubicExtConfig,
impl<'a, P> Sub<&'a mut CubicExtField<P>> for CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
Source§impl<'a, P> Sub<&'a mut QuadExtField<P>> for QuadExtField<P>where
P: QuadExtConfig,
impl<'a, P> Sub<&'a mut QuadExtField<P>> for QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
Source§impl<'b, P> Sub<CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
impl<'b, P> Sub<CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
Source§impl<'b, P> Sub<QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
impl<'b, P> Sub<QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
Source§impl<F, L> Sub<&FieldElement<F>> for &Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<&FieldElement<F>> for &Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<F, L> Sub<&FieldElement<F>> for Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<&FieldElement<F>> for Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<F, L> Sub<&FieldElement<L>> for &lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
impl<F, L> Sub<&FieldElement<L>> for &lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
Subtraction operator overloading for field elements*/
type Output = FieldElement<L>
Source§impl<F, L> Sub<&FieldElement<L>> for lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
impl<F, L> Sub<&FieldElement<L>> for lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
type Output = FieldElement<L>
Source§impl<F, L> Sub<&Polynomial<FieldElement<L>>> for &lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<&Polynomial<FieldElement<L>>> for &lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<F, L> Sub<&Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<&Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<F, L> Sub<&Polynomial<FieldElement<L>>> for lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<&Polynomial<FieldElement<L>>> for lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<F, L> Sub<&Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<&Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<F, L> Sub<FieldElement<F>> for &Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<FieldElement<F>> for &Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<F, L> Sub<FieldElement<F>> for Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<FieldElement<F>> for Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<F, L> Sub<FieldElement<L>> for &lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
impl<F, L> Sub<FieldElement<L>> for &lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
type Output = FieldElement<L>
Source§impl<F, L> Sub<FieldElement<L>> for lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
impl<F, L> Sub<FieldElement<L>> for lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
type Output = FieldElement<L>
Source§impl<F, L> Sub<Polynomial<FieldElement<L>>> for &lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<Polynomial<FieldElement<L>>> for &lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<F, L> Sub<Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<F, L> Sub<Polynomial<FieldElement<L>>> for lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<Polynomial<FieldElement<L>>> for lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<F, L> Sub<Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Sub<Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
Source§impl<MOD, const LIMBS: usize> Sub<&Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Sub<&Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
Source§impl<MOD, const LIMBS: usize> Sub<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Sub<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
Source§impl<MOD, const LIMBS: usize> Sub<Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Sub<Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
Source§impl<P> Sub for CubicExtField<P>where
P: CubicExtConfig,
impl<P> Sub for CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
Source§impl<P> Sub for QuadExtField<P>where
P: QuadExtConfig,
impl<P> Sub for QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
Source§impl<T, R> Sub for ReducedInt<T, R>
impl<T, R> Sub for ReducedInt<T, R>
type Output = ReducedInt<T, R>
Source§impl<T, R> Sub<&ReducedInt<T, R>> for &ReducedInt<T, R>
impl<T, R> Sub<&ReducedInt<T, R>> for &ReducedInt<T, R>
type Output = ReducedInt<T, R>
Source§impl<T, R> Sub<&ReducedInt<T, R>> for ReducedInt<T, R>
impl<T, R> Sub<&ReducedInt<T, R>> for ReducedInt<T, R>
type Output = ReducedInt<T, R>
Source§impl<T, R> Sub<ReducedInt<T, R>> for &ReducedInt<T, R>
impl<T, R> Sub<ReducedInt<T, R>> for &ReducedInt<T, R>
type Output = ReducedInt<T, R>
Source§impl<T, R> Sub<T> for ReducedInt<T, R>
impl<T, R> Sub<T> for ReducedInt<T, R>
type Output = ReducedInt<T, R>
Source§impl<Ul, Bl, Ur> Sub<Ur> for UInt<Ul, Bl>
impl<Ul, Bl, Ur> Sub<Ur> for UInt<Ul, Bl>
Subtracting unsigned integers. We just do our PrivateSub
and then Trim
the output.