Last active
October 7, 2018 12:58
-
-
Save magnet/06db0bb60bcb837872e73d518707d0e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops; | |
#[derive(Debug)] | |
struct Point(i32, i32); | |
impl ops::Add<Point> for Point { | |
type Output = Point; | |
fn add(self, _rhs: Point) -> Point { | |
Point(self.0 + _rhs.0, self.1 + _rhs.1) | |
} | |
} | |
fn main() { | |
let p1 = Point(5, 6); | |
println!("p1: {:?}", p1); | |
let p2 = Point(5, 4); | |
println!("p2: {:?}", p2); | |
let p3 = p1 + p2; | |
println!("p3: {:?}", p3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment