| 1 |
|
| 2 |
. |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#[macro_use] extern crate custom_derive; |
| 11 |
#[macro_use] extern crate newtype_derive; |
| 12 |
|
| 13 |
custom_derive! { |
| 14 |
#[derive(Copy, Clone, Eq, PartialEq, Debug, |
| 15 |
NewtypeAdd(*), |
| 16 |
NewtypeNeg(*), |
| 17 |
NewtypeFrom |
| 18 |
)] |
| 19 |
pub struct Dummy(i32); |
| 20 |
} |
| 21 |
|
| 22 |
custom_derive! { |
| 23 |
#[derive(Copy, Clone, Eq, PartialEq, Debug, |
| 24 |
NewtypeAdd(*), |
| 25 |
NewtypeNeg(*), |
| 26 |
NewtypeFrom |
| 27 |
)] |
| 28 |
pub struct DummyPub(pub i32); |
| 29 |
} |
| 30 |
|
| 31 |
#[test] |
| 32 |
fn test_arith() { |
| 33 |
let a = Dummy::from(4); |
| 34 |
let b = Dummy::from(7); |
| 35 |
let c = Dummy::from(11); |
| 36 |
|
| 37 |
assert_eq!(a + b, c); |
| 38 |
assert_eq!(&a + b, c); |
| 39 |
assert_eq!(a + &b, c); |
| 40 |
assert_eq!(&a + &b, c); |
| 41 |
|
| 42 |
assert_eq!(-a, Dummy::from(-4)); |
| 43 |
assert_eq!(-&a, Dummy::from(-4)); |
| 44 |
|
| 45 |
let _ = DummyPub(0); |
| 46 |
} |