Guest User

Untitled

a guest
Nov 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. use std::ops::Add;
  2.  
  3. struct Point {
  4. x: i32,
  5. y: i32,
  6. }
  7.  
  8. impl Add for Point {
  9. type Output = Point;
  10.  
  11. fn add(self, other: Point) -> Point {
  12. Point { x: self.x + other.x, y: self.y + other.y }
  13. }
  14. }
  15.  
  16. fn main() {
  17. let p1 = Point { x: 1, y: 0 };
  18. let p2 = Point { x: 2, y: 3 };
  19.  
  20. let p3 = p1 + p2;
  21. println!("Point: x = {}, y = {}", p3.x, p3.y);
  22. }
Add Comment
Please, Sign In to add comment