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<&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<f32>> for LittleEndian<f32>
impl Sub<&LittleEndian<f64>> for &LittleEndian<f64>
impl Sub<&LittleEndian<f64>> for LittleEndian<f64>
impl Sub<&LittleEndian<i16>> for &LittleEndian<i16>
impl Sub<&LittleEndian<i16>> for LittleEndian<i16>
impl Sub<&LittleEndian<i32>> for &LittleEndian<i32>
impl Sub<&LittleEndian<i32>> for LittleEndian<i32>
impl Sub<&LittleEndian<i64>> for &LittleEndian<i64>
impl Sub<&LittleEndian<i64>> for LittleEndian<i64>
impl Sub<&LittleEndian<u16>> for &LittleEndian<u16>
impl Sub<&LittleEndian<u16>> for LittleEndian<u16>
impl Sub<&LittleEndian<u32>> for &LittleEndian<u32>
impl Sub<&LittleEndian<u32>> for LittleEndian<u32>
impl Sub<&LittleEndian<u64>> for &LittleEndian<u64>
impl Sub<&LittleEndian<u64>> for LittleEndian<u64>
impl Sub<&NativeEndian<f32>> for &NativeEndian<f32>
impl Sub<&NativeEndian<f32>> for NativeEndian<f32>
impl Sub<&NativeEndian<f64>> for &NativeEndian<f64>
impl Sub<&NativeEndian<f64>> for NativeEndian<f64>
impl Sub<&NativeEndian<i16>> for &NativeEndian<i16>
impl Sub<&NativeEndian<i16>> for NativeEndian<i16>
impl Sub<&NativeEndian<i32>> for &NativeEndian<i32>
impl Sub<&NativeEndian<i32>> for NativeEndian<i32>
impl Sub<&NativeEndian<i64>> for &NativeEndian<i64>
impl Sub<&NativeEndian<i64>> for NativeEndian<i64>
impl Sub<&NativeEndian<u16>> for &NativeEndian<u16>
impl Sub<&NativeEndian<u16>> for NativeEndian<u16>
impl Sub<&NativeEndian<u32>> for &NativeEndian<u32>
impl Sub<&NativeEndian<u32>> for NativeEndian<u32>
impl Sub<&NativeEndian<u64>> for &NativeEndian<u64>
impl Sub<&NativeEndian<u64>> for NativeEndian<u64>
impl Sub<LittleEndian<f32>> for &LittleEndian<f32>
impl Sub<LittleEndian<f32>> for LittleEndian<f32>
impl Sub<LittleEndian<f64>> for &LittleEndian<f64>
impl Sub<LittleEndian<f64>> for LittleEndian<f64>
impl Sub<LittleEndian<i16>> for &LittleEndian<i16>
impl Sub<LittleEndian<i16>> for LittleEndian<i16>
impl Sub<LittleEndian<i32>> for &LittleEndian<i32>
impl Sub<LittleEndian<i32>> for LittleEndian<i32>
impl Sub<LittleEndian<i64>> for &LittleEndian<i64>
impl Sub<LittleEndian<i64>> for LittleEndian<i64>
impl Sub<LittleEndian<u16>> for &LittleEndian<u16>
impl Sub<LittleEndian<u16>> for LittleEndian<u16>
impl Sub<LittleEndian<u32>> for &LittleEndian<u32>
impl Sub<LittleEndian<u32>> for LittleEndian<u32>
impl Sub<LittleEndian<u64>> for &LittleEndian<u64>
impl Sub<LittleEndian<u64>> for LittleEndian<u64>
impl Sub<NativeEndian<f32>> for &NativeEndian<f32>
impl Sub<NativeEndian<f32>> for NativeEndian<f32>
impl Sub<NativeEndian<f64>> for &NativeEndian<f64>
impl Sub<NativeEndian<f64>> for NativeEndian<f64>
impl Sub<NativeEndian<i16>> for &NativeEndian<i16>
impl Sub<NativeEndian<i16>> for NativeEndian<i16>
impl Sub<NativeEndian<i32>> for &NativeEndian<i32>
impl Sub<NativeEndian<i32>> for NativeEndian<i32>
impl Sub<NativeEndian<i64>> for &NativeEndian<i64>
impl Sub<NativeEndian<i64>> for NativeEndian<i64>
impl Sub<NativeEndian<u16>> for &NativeEndian<u16>
impl Sub<NativeEndian<u16>> for NativeEndian<u16>
impl Sub<NativeEndian<u32>> for &NativeEndian<u32>
impl Sub<NativeEndian<u32>> for NativeEndian<u32>
impl Sub<NativeEndian<u64>> for &NativeEndian<u64>
impl Sub<NativeEndian<u64>> for NativeEndian<u64>
sourceimpl<T> Sub<T> for Pages where
T: Into<Self>,