Guest User

Untitled

a guest
Jul 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #![allow(unused)]
  2. fn main() {
  3. use std::ops::Add;
  4.  
  5. #[derive(Debug, PartialEq)]
  6. struct Point {
  7. x: i32,
  8. y: i32,
  9. }
  10.  
  11. impl<'a> Add for &'a Point {
  12. type Output = Point;
  13.  
  14. fn add<'b>(self, other: &'b Point) -> Point {
  15. Point {
  16. x: self.x + other.x,
  17. y: self.y + other.y,
  18. }
  19. }
  20. }
  21.  
  22. let p1 = Point{ x: 0, y: 1 };
  23. let p2 = Point{ x: 2, y: 3 };
  24.  
  25. let p3 = &p1 + &p2;
  26.  
  27. println!("{:?}, {:?}, {:?}", p1, p2, p3);
  28. }
Add Comment
Please, Sign In to add comment