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
use crate::{OrdMask, WithMin};
macro_rules! impl_op {
($op: ident
$(#[$meta:meta])*
fn $fn_name:ident($self:ident, $rhs:ident) $body: block
) => {
impl_op! { $op for OrdMask<T> { $( #[$meta])* fn $fn_name($self, $rhs) $body } }
impl_op! { $op for &OrdMask<T> {
$(#[$meta])*
#[allow(clippy::useless_asref)]
fn $fn_name($self, $rhs) $body
} }
};
($op: ident for $lt:ty {
$(#[$meta:meta])*
fn $fn_name:ident($self:ident, $rhs:ident) $body: block
}) => {
impl<T, R> std::ops::$op<R> for $lt
where
R: AsRef<OrdMask<T>>,
T: Ord + Clone + WithMin,
{
type Output = OrdMask<T>;
$(#[$meta])*
fn $fn_name($self, $rhs: R) -> Self::Output $body
}
};
}
impl_op! { BitOr
/// Create a new [`OrdMask`] representing the union of `self` and `rhs`.
///
/// Equivalent to `OrdMask::union(&[self.as_ref(), rhs.as_ref()])`.
///
/// Use [`OrdMask::union(...)`](OrdMask::union) when there are more than two masks to combine.
fn bitor(self, rhs) { OrdMask::union(&[self.as_ref(), rhs.as_ref()]) }
}
impl_op! { BitAnd
/// Create a new [`OrdMask`] representing the intersection of `self` and `rhs`.
///
/// Equivalent to `OrdMask::intersection(&[self.as_ref(), rhs.as_ref()])`.
///
/// Use [`OrdMask::intersection(...)`](OrdMask::intersection) when there are more than two masks to combine.
fn bitand(self, rhs) { OrdMask::intersection(&[self.as_ref(), rhs.as_ref()]) }
}
impl_op! { BitXor
/// Create a new [`OrdMask`] representing the symmetric difference of `self` and `rhs`.
///
/// Equivalent to [`self.symmetric_difference(rhs.as_ref())`](OrdMask::symmetric_difference)
fn bitxor(self, rhs) { self.symmetric_difference(rhs.as_ref()) }
}
impl_op! { Sub
/// Create a new [`OrdMask`] representing `self` minus `rhs`.
///
/// Equivalent to `self.minus(&[rhs.as_ref()])`
///
/// Use [`a.minus(...)`](OrdMask::minus) when there are more than one mask to remove.
fn sub(self, rhs) { self.minus(&[rhs.as_ref()]) }
}
impl<T: Ord + Clone + WithMin> std::ops::Not for OrdMask<T> {
type Output = OrdMask<T>;
/// Consume `self` and return its complement.
///
/// Equivalent to `self.to_complement()`. See [`OrdMask::to_complement`].
fn not(self) -> Self::Output {
self.to_complement()
}
}
impl<T: Ord + Clone + WithMin> std::ops::Not for &OrdMask<T> {
type Output = OrdMask<T>;
/// Create a new [`OrdMask`] representing the complement of `self`.
///
/// Equivalent to [`self.complement()`](OrdMask::complement).
fn not(self) -> Self::Output {
self.complement()
}
}