add sub
This commit is contained in:
@@ -15,11 +15,24 @@ impl std::ops::Add<Point> for Point {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Sub<Point> 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user