Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ops::*;
- use std::fmt::Debug;
- #[derive(Eq, PartialEq, Debug, Copy, Clone)]
- struct Point {
- x: u32,
- y: u32,
- }
- impl Add for Point {
- type Output = Point;
- fn add(self, other: Point) -> Self {
- Point {
- x: self.x + other.x,
- y: self.y + other.y,
- }
- }
- }
- fn addable<A: Add + Debug>(a: A, b: A) -> A::Output {
- println!("{:?} + {:?} = {:?}", a, b, a + b);
- a + b
- }
- fn main() {
- let p1: Point = Point { x: 1, y: 1 };
- let p2: Point = Point { x: 2, y: 2 };
- assert!((p1 + p2) == Point { x: 3, y: 3 });
- assert!(addable(p1, p2) == Point { x: 3, y: 3 });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement