macros.rs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. macro_rules! define_add_variants {
  2. (LHS = $lhs:ty, RHS = $rhs:ty, Output = $out:ty) => {
  3. impl<'b> Add<&'b $rhs> for $lhs {
  4. type Output = $out;
  5. fn add(self, rhs: &'b $rhs) -> $out {
  6. &self + rhs
  7. }
  8. }
  9. impl<'a> Add<$rhs> for &'a $lhs {
  10. type Output = $out;
  11. fn add(self, rhs: $rhs) -> $out {
  12. self + &rhs
  13. }
  14. }
  15. impl Add<$rhs> for $lhs {
  16. type Output = $out;
  17. fn add(self, rhs: $rhs) -> $out {
  18. &self + &rhs
  19. }
  20. }
  21. };
  22. }
  23. macro_rules! define_sub_variants {
  24. (LHS = $lhs:ty, RHS = $rhs:ty, Output = $out:ty) => {
  25. impl<'b> Sub<&'b $rhs> for $lhs {
  26. type Output = $out;
  27. fn sub(self, rhs: &'b $rhs) -> $out {
  28. &self - rhs
  29. }
  30. }
  31. impl<'a> Sub<$rhs> for &'a $lhs {
  32. type Output = $out;
  33. fn sub(self, rhs: $rhs) -> $out {
  34. self - &rhs
  35. }
  36. }
  37. impl Sub<$rhs> for $lhs {
  38. type Output = $out;
  39. fn sub(self, rhs: $rhs) -> $out {
  40. &self - &rhs
  41. }
  42. }
  43. };
  44. }
  45. macro_rules! define_mul_variants {
  46. (LHS = $lhs:ty, RHS = $rhs:ty, Output = $out:ty) => {
  47. impl<'b> Mul<&'b $rhs> for $lhs {
  48. type Output = $out;
  49. fn mul(self, rhs: &'b $rhs) -> $out {
  50. &self * rhs
  51. }
  52. }
  53. impl<'a> Mul<$rhs> for &'a $lhs {
  54. type Output = $out;
  55. fn mul(self, rhs: $rhs) -> $out {
  56. self * &rhs
  57. }
  58. }
  59. impl Mul<$rhs> for $lhs {
  60. type Output = $out;
  61. fn mul(self, rhs: $rhs) -> $out {
  62. &self * &rhs
  63. }
  64. }
  65. };
  66. }