| 1 |
#![cfg_attr(not(feature = "std"), no_std)] |
| 2 |
#![allow(dead_code)] // some code is tested for type checking only |
| 3 |
|
| 4 |
use derive_more::Sum; |
| 5 |
|
| 6 |
#[derive(Sum)] |
| 7 |
struct MyInts(i32, i64); |
| 8 |
|
| 9 |
// `Add` implementation is required for `Sum`. |
| 10 |
impl ::core::ops::Add for MyInts { |
| 11 |
type Output = MyInts; |
| 12 |
#[inline] |
| 13 |
fn add(self, rhs: MyInts) -> MyInts { |
| 14 |
MyInts(self.0.add(rhs.0), self.1.add(rhs.1)) |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
#[derive(Sum)] |
| 19 |
struct Point2D { |
| 20 |
x: i32, |
| 21 |
y: i32, |
| 22 |
} |
| 23 |
|
| 24 |
// `Add` implementation is required for `Sum`. |
| 25 |
impl ::core::ops::Add for Point2D { |
| 26 |
type Output = Point2D; |
| 27 |
#[inline] |
| 28 |
fn add(self, rhs: Point2D) -> Point2D { |
| 29 |
Point2D { |
| 30 |
x: self.x.add(rhs.x), |
| 31 |
y: self.y.add(rhs.y), |
| 32 |
} |
| 33 |
} |
| 34 |
} |