Debian Codegraph @

third_party/rust/derive_more/tests/sum.rs

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