From c13042768b82e46f737dcaceaba6ec60161a5dd1 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Wed, 22 Jan 2020 22:54:03 +0800 Subject: [PATCH] add sub --- ops-test/src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ops-test/src/main.rs b/ops-test/src/main.rs index 3edf04a..46bf68c 100644 --- a/ops-test/src/main.rs +++ b/ops-test/src/main.rs @@ -15,11 +15,24 @@ impl std::ops::Add for Point { } } +impl std::ops::Sub for Point { + type Output = Self; + + fn sub(self, rhs: Self) -> Self { + Point { + x: self.x - rhs.x, + y: self.y - rhs.y, + } + } +} + fn main() { let a = Point { x: 1, y: 2, }; let b = Point { x: 2, y: 4, }; - let c = a.clone() + b; + let c = a.clone() + b.clone(); + let d = a.clone() - b.clone(); println!("{:?}", a); - // println!("{:?}", b); + println!("{:?}", b); println!("{:?}", c); + println!("{:?}", d); }