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
.
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 });
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,
}
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 });
The resulting type after applying the -
operator.
Performs the -
operation.
impl Sub<LittleEndian<f32>> for LittleEndian<f32>
impl Sub<LittleEndian<f64>> for LittleEndian<f64>
impl Sub<LittleEndian<i16>> for LittleEndian<i16>
impl Sub<LittleEndian<i32>> for LittleEndian<i32>
impl Sub<LittleEndian<i64>> for LittleEndian<i64>
impl Sub<LittleEndian<u16>> for LittleEndian<u16>
impl Sub<LittleEndian<u32>> for LittleEndian<u32>
impl Sub<LittleEndian<u64>> for LittleEndian<u64>
impl Sub<NativeEndian<f32>> for NativeEndian<f32>
impl Sub<NativeEndian<f64>> for NativeEndian<f64>
impl Sub<NativeEndian<i16>> for NativeEndian<i16>
impl Sub<NativeEndian<i32>> for NativeEndian<i32>
impl Sub<NativeEndian<i64>> for NativeEndian<i64>
impl Sub<NativeEndian<u16>> for NativeEndian<u16>
impl Sub<NativeEndian<u32>> for NativeEndian<u32>
impl Sub<NativeEndian<u64>> for NativeEndian<u64>
impl<'_> Sub<&'_ BigEndian<f32>> for BigEndian<f32>
impl<'_> Sub<&'_ BigEndian<f64>> for BigEndian<f64>
impl<'_> Sub<&'_ BigEndian<i16>> for BigEndian<i16>
impl<'_> Sub<&'_ BigEndian<i32>> for BigEndian<i32>
impl<'_> Sub<&'_ BigEndian<i64>> for BigEndian<i64>
impl<'_> Sub<&'_ BigEndian<u16>> for BigEndian<u16>
impl<'_> Sub<&'_ BigEndian<u32>> for BigEndian<u32>
impl<'_> Sub<&'_ BigEndian<u64>> for BigEndian<u64>
impl<'_> Sub<&'_ LittleEndian<f32>> for LittleEndian<f32>
impl<'_> Sub<&'_ LittleEndian<f64>> for LittleEndian<f64>
impl<'_> Sub<&'_ LittleEndian<i16>> for LittleEndian<i16>
impl<'_> Sub<&'_ LittleEndian<i32>> for LittleEndian<i32>
impl<'_> Sub<&'_ LittleEndian<i64>> for LittleEndian<i64>
impl<'_> Sub<&'_ LittleEndian<i128>> for LittleEndian<i128>
impl<'_> Sub<&'_ LittleEndian<u16>> for LittleEndian<u16>
impl<'_> Sub<&'_ LittleEndian<u32>> for LittleEndian<u32>
impl<'_> Sub<&'_ LittleEndian<u64>> for LittleEndian<u64>
impl<'_> Sub<&'_ LittleEndian<u128>> for LittleEndian<u128>
impl<'_> Sub<&'_ NativeEndian<f32>> for NativeEndian<f32>
impl<'_> Sub<&'_ NativeEndian<f64>> for NativeEndian<f64>
impl<'_> Sub<&'_ NativeEndian<i16>> for NativeEndian<i16>
impl<'_> Sub<&'_ NativeEndian<i32>> for NativeEndian<i32>
impl<'_> Sub<&'_ NativeEndian<i64>> for NativeEndian<i64>
impl<'_> Sub<&'_ NativeEndian<i128>> for NativeEndian<i128>
impl<'_> Sub<&'_ NativeEndian<u16>> for NativeEndian<u16>
impl<'_> Sub<&'_ NativeEndian<u32>> for NativeEndian<u32>
impl<'_> Sub<&'_ NativeEndian<u64>> for NativeEndian<u64>
impl<'_> Sub<&'_ NativeEndian<u128>> for NativeEndian<u128>
impl<'_> Sub<BigEndian<f32>> for &'_ BigEndian<f32>
impl<'_> Sub<BigEndian<f64>> for &'_ BigEndian<f64>
impl<'_> Sub<BigEndian<i16>> for &'_ BigEndian<i16>
impl<'_> Sub<BigEndian<i32>> for &'_ BigEndian<i32>
impl<'_> Sub<BigEndian<i64>> for &'_ BigEndian<i64>
impl<'_> Sub<BigEndian<u16>> for &'_ BigEndian<u16>
impl<'_> Sub<BigEndian<u32>> for &'_ BigEndian<u32>
impl<'_> Sub<BigEndian<u64>> for &'_ BigEndian<u64>
impl<'_> Sub<LittleEndian<f32>> for &'_ LittleEndian<f32>
impl<'_> Sub<LittleEndian<f64>> for &'_ LittleEndian<f64>
impl<'_> Sub<LittleEndian<i16>> for &'_ LittleEndian<i16>
impl<'_> Sub<LittleEndian<i32>> for &'_ LittleEndian<i32>
impl<'_> Sub<LittleEndian<i64>> for &'_ LittleEndian<i64>
impl<'_> Sub<LittleEndian<i128>> for &'_ LittleEndian<i128>
impl<'_> Sub<LittleEndian<u16>> for &'_ LittleEndian<u16>
impl<'_> Sub<LittleEndian<u32>> for &'_ LittleEndian<u32>
impl<'_> Sub<LittleEndian<u64>> for &'_ LittleEndian<u64>
impl<'_> Sub<LittleEndian<u128>> for &'_ LittleEndian<u128>
impl<'_> Sub<NativeEndian<f32>> for &'_ NativeEndian<f32>
impl<'_> Sub<NativeEndian<f64>> for &'_ NativeEndian<f64>
impl<'_> Sub<NativeEndian<i16>> for &'_ NativeEndian<i16>
impl<'_> Sub<NativeEndian<i32>> for &'_ NativeEndian<i32>
impl<'_> Sub<NativeEndian<i64>> for &'_ NativeEndian<i64>
impl<'_> Sub<NativeEndian<i128>> for &'_ NativeEndian<i128>
impl<'_> Sub<NativeEndian<u16>> for &'_ NativeEndian<u16>
impl<'_> Sub<NativeEndian<u32>> for &'_ NativeEndian<u32>
impl<'_> Sub<NativeEndian<u64>> for &'_ NativeEndian<u64>
impl<'_> Sub<NativeEndian<u128>> for &'_ NativeEndian<u128>
impl<'_, '_> Sub<&'_ f32> for &'_ BigEndian<f32>
impl<'_, '_> Sub<&'_ f32> for &'_ LittleEndian<f32>
impl<'_, '_> Sub<&'_ f32> for &'_ NativeEndian<f32>
impl<'_, '_> Sub<&'_ f64> for &'_ BigEndian<f64>
impl<'_, '_> Sub<&'_ f64> for &'_ LittleEndian<f64>
impl<'_, '_> Sub<&'_ f64> for &'_ NativeEndian<f64>
impl<'_, '_> Sub<&'_ i16> for &'_ BigEndian<i16>
impl<'_, '_> Sub<&'_ i16> for &'_ LittleEndian<i16>
impl<'_, '_> Sub<&'_ i16> for &'_ NativeEndian<i16>
impl<'_, '_> Sub<&'_ i32> for &'_ BigEndian<i32>
impl<'_, '_> Sub<&'_ i32> for &'_ LittleEndian<i32>
impl<'_, '_> Sub<&'_ i32> for &'_ NativeEndian<i32>
impl<'_, '_> Sub<&'_ i64> for &'_ BigEndian<i64>
impl<'_, '_> Sub<&'_ i64> for &'_ LittleEndian<i64>
impl<'_, '_> Sub<&'_ i64> for &'_ NativeEndian<i64>
impl<'_, '_> Sub<&'_ u16> for &'_ BigEndian<u16>
impl<'_, '_> Sub<&'_ u16> for &'_ LittleEndian<u16>
impl<'_, '_> Sub<&'_ u16> for &'_ NativeEndian<u16>
impl<'_, '_> Sub<&'_ u32> for &'_ BigEndian<u32>
impl<'_, '_> Sub<&'_ u32> for &'_ LittleEndian<u32>
impl<'_, '_> Sub<&'_ u32> for &'_ NativeEndian<u32>
impl<'_, '_> Sub<&'_ u64> for &'_ BigEndian<u64>
impl<'_, '_> Sub<&'_ u64> for &'_ LittleEndian<u64>
impl<'_, '_> Sub<&'_ u64> for &'_ NativeEndian<u64>
impl<'_, '_> Sub<&'_ BigEndian<f32>> for &'_ f32
impl<'_, '_> Sub<&'_ BigEndian<f32>> for &'_ BigEndian<f32>
impl<'_, '_> Sub<&'_ BigEndian<f64>> for &'_ f64
impl<'_, '_> Sub<&'_ BigEndian<f64>> for &'_ BigEndian<f64>
impl<'_, '_> Sub<&'_ BigEndian<i16>> for &'_ i16
impl<'_, '_> Sub<&'_ BigEndian<i16>> for &'_ BigEndian<i16>
impl<'_, '_> Sub<&'_ BigEndian<i32>> for &'_ i32
impl<'_, '_> Sub<&'_ BigEndian<i32>> for &'_ BigEndian<i32>
impl<'_, '_> Sub<&'_ BigEndian<i64>> for &'_ i64
impl<'_, '_> Sub<&'_ BigEndian<i64>> for &'_ BigEndian<i64>
impl<'_, '_> Sub<&'_ BigEndian<i128>> for &'_ BigEndian<i128>
impl<'_, '_> Sub<&'_ BigEndian<u16>> for &'_ u16
impl<'_, '_> Sub<&'_ BigEndian<u16>> for &'_ BigEndian<u16>
impl<'_, '_> Sub<&'_ BigEndian<u32>> for &'_ u32
impl<'_, '_> Sub<&'_ BigEndian<u32>> for &'_ BigEndian<u32>
impl<'_, '_> Sub<&'_ BigEndian<u64>> for &'_ u64
impl<'_, '_> Sub<&'_ BigEndian<u64>> for &'_ BigEndian<u64>
impl<'_, '_> Sub<&'_ BigEndian<u128>> for &'_ BigEndian<u128>
impl<'_, '_> Sub<&'_ LittleEndian<f32>> for &'_ f32
impl<'_, '_> Sub<&'_ LittleEndian<f32>> for &'_ LittleEndian<f32>
impl<'_, '_> Sub<&'_ LittleEndian<f64>> for &'_ f64
impl<'_, '_> Sub<&'_ LittleEndian<f64>> for &'_ LittleEndian<f64>
impl<'_, '_> Sub<&'_ LittleEndian<i16>> for &'_ i16
impl<'_, '_> Sub<&'_ LittleEndian<i16>> for &'_ LittleEndian<i16>
impl<'_, '_> Sub<&'_ LittleEndian<i32>> for &'_ i32
impl<'_, '_> Sub<&'_ LittleEndian<i32>> for &'_ LittleEndian<i32>
impl<'_, '_> Sub<&'_ LittleEndian<i64>> for &'_ i64
impl<'_, '_> Sub<&'_ LittleEndian<i64>> for &'_ LittleEndian<i64>
impl<'_, '_> Sub<&'_ LittleEndian<i128>> for &'_ LittleEndian<i128>
impl<'_, '_> Sub<&'_ LittleEndian<u16>> for &'_ u16
impl<'_, '_> Sub<&'_ LittleEndian<u16>> for &'_ LittleEndian<u16>
impl<'_, '_> Sub<&'_ LittleEndian<u32>> for &'_ u32
impl<'_, '_> Sub<&'_ LittleEndian<u32>> for &'_ LittleEndian<u32>
impl<'_, '_> Sub<&'_ LittleEndian<u64>> for &'_ u64
impl<'_, '_> Sub<&'_ LittleEndian<u64>> for &'_ LittleEndian<u64>
impl<'_, '_> Sub<&'_ LittleEndian<u128>> for &'_ LittleEndian<u128>
impl<'_, '_> Sub<&'_ NativeEndian<f32>> for &'_ f32
impl<'_, '_> Sub<&'_ NativeEndian<f32>> for &'_ NativeEndian<f32>
impl<'_, '_> Sub<&'_ NativeEndian<f64>> for &'_ f64
impl<'_, '_> Sub<&'_ NativeEndian<f64>> for &'_ NativeEndian<f64>
impl<'_, '_> Sub<&'_ NativeEndian<i16>> for &'_ i16
impl<'_, '_> Sub<&'_ NativeEndian<i16>> for &'_ NativeEndian<i16>
impl<'_, '_> Sub<&'_ NativeEndian<i32>> for &'_ i32
impl<'_, '_> Sub<&'_ NativeEndian<i32>> for &'_ NativeEndian<i32>
impl<'_, '_> Sub<&'_ NativeEndian<i64>> for &'_ i64
impl<'_, '_> Sub<&'_ NativeEndian<i64>> for &'_ NativeEndian<i64>
impl<'_, '_> Sub<&'_ NativeEndian<i128>> for &'_ NativeEndian<i128>
impl<'_, '_> Sub<&'_ NativeEndian<u16>> for &'_ u16
impl<'_, '_> Sub<&'_ NativeEndian<u16>> for &'_ NativeEndian<u16>
impl<'_, '_> Sub<&'_ NativeEndian<u32>> for &'_ u32
impl<'_, '_> Sub<&'_ NativeEndian<u32>> for &'_ NativeEndian<u32>
impl<'_, '_> Sub<&'_ NativeEndian<u64>> for &'_ u64
impl<'_, '_> Sub<&'_ NativeEndian<u64>> for &'_ NativeEndian<u64>
impl<'_, '_> Sub<&'_ NativeEndian<u128>> for &'_ NativeEndian<u128>