bigdecimal/macros.rs
1// \file src/macros.rs
2//! macros for
3/*
4macro_rules! forward_val_val_binop {
5 (impl $imp:ident for $res:ty, $method:ident) => {
6 impl $imp<$res> for $res {
7 type Output = $res;
8
9 #[inline]
10 fn $method(self, other: $res) -> $res {
11 // forward to val-ref
12 $imp::$method(self, &other)
13 }
14 }
15 };
16}
17
18*/
19macro_rules! forward_ref_val_binop {
20 (impl $imp:ident for $res:ty, $method:ident) => {
21 impl<'a> $imp<$res> for &'a $res {
22 type Output = $res;
23
24 #[inline]
25 fn $method(self, other: $res) -> $res {
26 // forward to ref-ref
27 $imp::$method(self, &other)
28 }
29 }
30 };
31}
32
33macro_rules! forward_communative_binop {
34 (impl $trait:ident<$t1:ty>::$method:ident for $t2:ty) => {
35 forward_communative_binop!(
36 impl $trait<$t1>::$method for $t2; Output=BigDecimal
37 );
38 };
39 (impl $trait:ident<$t1:ty>::$method:ident for $t2:ty; Output=$output:ty) => {
40 impl $trait<$t1> for $t2 {
41 type Output = $output;
42
43 #[inline]
44 fn $method(self, rhs: $t1) -> Self::Output {
45 // swap operands
46 $trait::$method(rhs, self)
47 }
48 }
49 };
50}
51
52/*
53macro_rules! forward_val_ref_binop {
54 (impl $imp:ident for $res:ty, $method:ident) => {
55 impl<'a> $imp<&'a $res> for $res {
56 type Output = $res;
57
58 #[inline]
59 fn $method(self, other: &$res) -> $res {
60 // forward to ref-ref
61 $imp::$method(&self, other)
62 }
63 }
64 };
65}
66
67// Forward everything to ref-ref, when reusing storage is not helpful
68macro_rules! forward_all_binop_to_ref_ref {
69 (impl $imp:ident for $res:ty, $method:ident) => {
70 forward_val_val_binop!(impl $imp for $res, $method);
71 forward_val_ref_binop!(impl $imp for $res, $method);
72 forward_ref_val_binop!(impl $imp for $res, $method);
73 };
74}
75*/