Skip to content

Instantly share code, notes, and snippets.

@magnet
Last active October 7, 2018 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnet/06db0bb60bcb837872e73d518707d0e5 to your computer and use it in GitHub Desktop.
Save magnet/06db0bb60bcb837872e73d518707d0e5 to your computer and use it in GitHub Desktop.
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