Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #[derive(Debug, Clone)]
  2. struct Point {
  3. x: i32,
  4. y: i32
  5. }
  6.  
  7. impl std::ops::Add<Point> for Point {
  8. type Output = Point;
  9.  
  10. fn add( self, other: Point ) -> Point {
  11. Point { x: self.x + other.x, y: self.y + other.y }
  12. }
  13. }
  14.  
  15. impl std::ops::Add<Box<Point>> for Point {
  16. type Output = Point;
  17.  
  18. fn add( self, other: Box<Point> ) -> Point {
  19. Point { x: self.x + other.x, y: self.y + other.y }
  20. }
  21. }
  22.  
  23. impl std::ops::Add<Point> for Box<Point> {
  24. type Output = Point;
  25.  
  26. fn add( self, other: Point ) -> Point {
  27. Point { x: self.x + other.x, y: self.y + other.y }
  28. }
  29. }
  30.  
  31. fn main() {
  32. let first_point: Point = Point { x: 1, y: 2 };
  33. let second_point: Box<Point> = Box::new( Point { x: 1, y: 1 } );
  34. let third_point: Box<Point> = second_point.clone();
  35. let fourth_point: Point = first_point + second_point + third_point;
  36.  
  37. println!( "{:?}", fourth_point );
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement