blob: 615eb31c5fa46e98fc8553e64a2019c871b57e7b (
plain) (
blame)
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
|
/// Implement the `Sub` trait based on existing `Neg` and `Add` impls.
macro_rules! sub_impl {
($a:ident - $b:ident -> $c:ident) => {
impl Sub<$b> for $a {
type Output = $c;
fn sub(self, other: $b) -> $c {
self + -other
}
}
};
}
/// Implement an assign trait based on an existing non-assign trait.
macro_rules! assign_impl {
($a:ident += $b:ident) => {
impl AddAssign<$b> for $a {
fn add_assign(&mut self, other: $b) {
*self = *self + other;
}
}
};
($a:ident -= $b:ident) => {
impl SubAssign<$b> for $a {
fn sub_assign(&mut self, other: $b) {
*self = *self - other;
}
}
};
($a:ident *= $b:ident) => {
impl MulAssign<$b> for $a {
fn mul_assign(&mut self, other: $b) {
*self = *self * other;
}
}
};
($a:ident /= $b:ident) => {
impl DivAssign<$b> for $a {
fn div_assign(&mut self, other: $b) {
*self = *self / other;
}
}
};
}
|