std::ops::Sub
Trait std::ops::Sub
#[lang = "sub"] pub trait Sub<RHS = Self> { type Output; fn sub(self, rhs: RHS) -> Self::Output; }
The subtraction operator -
.
Examples
This example creates a Point
struct that implements the Sub
trait, and then demonstrates subtracting two Point
s.
use std::ops::Sub; #[derive(Debug)] struct Point { x: i32, y: i32, } impl Sub for Point { type Output = Point; fn sub(self, other: Point) -> Point { Point { x: self.x - other.x, y: self.y - other.y, } } } impl PartialEq for Point { fn eq(&self, other: &Self) -> bool { self.x == other.x && self.y == other.y } } fn main() { assert_eq!(Point { x: 3, y: 3 } - Poi