1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! Helper macro for `RangeMapBlaze` binary-operator impls.
//!
//! Usage pattern:
//
// map_op!(
// bitand &, // Rust trait + symbol
// RangeMapBlaze<T, V>, // RHS concrete type
// /// One doc-comment that shows up on every impl.,
//
// |a, b| { /* owned vs owned */ },
// |a, &b| { /* owned vs &borrow */ },
// |&a, b| { /* &borrow vs owned */ },
// |&a,&b| { /* &borrow vs &bor */ },
// );
//
#[doc(hidden)]
#[macro_export]
macro_rules! map_op {
(
$trait_name:ident $symbol:tt,
$rhs:ty,
$(#[$meta:meta])*
$doc:literal,
|$a1:ident , $b1:ident| $body1:block,
|$a2:ident , & $b2:ident| $body2:block,
|& $a3:ident , $b3:ident| $body3:block,
|& $a4:ident , & $b4:ident| $body4:block $(,)?
) => {
// ---- owned ⊛ owned ----
$(#[$meta])*
#[doc=$doc]
impl<T, V> ::core::ops::$trait_name<$rhs>
for $crate::map::RangeMapBlaze<T, V>
where
T: $crate::Integer,
V: ::core::cmp::Eq + ::core::clone::Clone,
{
type Output = $crate::map::RangeMapBlaze<T, V>;
#[inline]
fn $symbol(self, rhs: $rhs) -> Self::Output {
let $a1 = self;
let $b1 = rhs;
$body1
}
}
// ---- owned ⊛ &borrowed ----
impl<T, V> ::core::ops::$trait_name<&$rhs>
for $crate::map::RangeMapBlaze<T, V>
where
T: $crate::Integer,
V: ::core::cmp::Eq + ::core::clone::Clone,
{
type Output = $crate::map::RangeMapBlaze<T, V>;
#[inline]
fn $symbol(self, rhs: &$rhs) -> Self::Output {
let $a2 = self;
let $b2 = rhs;
$body2
}
}
// ---- &borrowed ⊛ owned ----
impl<T, V> ::core::ops::$trait_name<$rhs>
for &$crate::map::RangeMapBlaze<T, V>
where
T: $crate::Integer,
V: ::core::cmp::Eq + ::core::clone::Clone,
{
type Output = $crate::map::RangeMapBlaze<T, V>;
#[inline]
fn $symbol(self, rhs: $rhs) -> Self::Output {
let $a3 = self;
let $b3 = rhs;
$body3
}
}
// ---- &borrowed ⊛ &borrowed ----
impl<T, V> ::core::ops::$trait_name<&$rhs>
for &$crate::map::RangeMapBlaze<T, V>
where
T: $crate::Integer,
V: ::core::cmp::Eq + ::core::clone::Clone,
{
type Output = $crate::map::RangeMapBlaze<T, V>;
#[inline]
fn $symbol(self, rhs: &$rhs) -> Self::Output {
let $a4 = self;
let $b4 = rhs;
$body4
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! map_unary_op {
(
$trait_name:ident $method:ident, // e.g. Not not
$out:ty, // output type
$(#[$meta:meta])* // doc attrs
$doc:literal, // doc string
|& $self_ident:ident| $body_ref:block // body for &self
$(,)? // optional trailing comma
) => {
// ---- impl for &RangeMapBlaze ----
$(#[$meta])*
#[doc=$doc]
impl<T, V> ::core::ops::$trait_name
for &$crate::map::RangeMapBlaze<T, V>
where
T: $crate::Integer,
V: ::core::cmp::Eq + ::core::clone::Clone,
{
type Output = $out;
#[inline]
fn $method(self) -> Self::Output {
let $self_ident = self;
$body_ref
}
}
// ---- impl for owned RangeMapBlaze (delegates) ----
impl<T, V> ::core::ops::$trait_name
for $crate::map::RangeMapBlaze<T, V>
where
T: $crate::Integer,
V: ::core::cmp::Eq + ::core::clone::Clone,
{
type Output = $out;
#[inline]
fn $method(self) -> Self::Output {
// forward to the &self implementation
(&self).$method()
}
}
};
}