Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ops::Add;
- struct Point {
- x: i32,
- y: i32,
- }
- impl Add for Point {
- type Output = Point;
- fn add(self, other: Point) -> Point {
- Point { x: self.x + other.x, y: self.y + other.y }
- }
- }
- fn main() {
- let p1 = Point { x: 1, y: 0 };
- let p2 = Point { x: 2, y: 3 };
- let p3 = p1 + p2;
- println!("Point: x = {}, y = {}", p3.x, p3.y);
- }
Add Comment
Please, Sign In to add comment