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
use crate::{
BoundedRange, BoundedSet, EmptyRange, LowerBoundedRange, LowerBoundedSet, RangeIntersection,
Rangetools, UnboundedRange, UnboundedSet, UpperBoundedRange, UpperBoundedSet,
};
impl<T, R> RangeIntersection<R, BoundedRange<T>> for BoundedRange<T>
where
R: Rangetools<Inner = BoundedRange<T>>,
T: Copy + Ord,
{
type Output = BoundedRange<T>;
fn intersection(self, other: R) -> Self::Output {
let other = other.to_inner();
BoundedRange::new(self.start.max(other.start), self.end.min(other.end))
}
}
impl<T, R> RangeIntersection<R, BoundedSet<T>> for BoundedRange<T>
where
R: Rangetools<Inner = BoundedSet<T>>,
T: Copy + Ord,
{
type Output = BoundedSet<T>;
fn intersection(self, other: R) -> Self::Output {
RangeIntersection::intersection(other.to_inner(), self)
}
}
impl<T, R> RangeIntersection<R, LowerBoundedRange<T>> for BoundedRange<T>
where
R: Rangetools<Inner = LowerBoundedRange<T>>,
T: Copy + Ord,
{
type Output = BoundedRange<T>;
fn intersection(self, other: R) -> Self::Output {
BoundedRange::new(self.start.max(other.to_inner().start), self.end)
}
}
impl<T, R> RangeIntersection<R, LowerBoundedSet<T>> for BoundedRange<T>
where
R: Rangetools<Inner = LowerBoundedSet<T>>,
T: Copy + Ord,
{
type Output = BoundedSet<T>;
fn intersection(self, other: R) -> Self::Output {
RangeIntersection::intersection(other.to_inner(), self)
}
}
impl<T, R> RangeIntersection<R, UpperBoundedRange<T>> for BoundedRange<T>
where
R: Rangetools<Inner = UpperBoundedRange<T>>,
T: Copy + Ord,
{
type Output = BoundedRange<T>;
fn intersection(self, other: R) -> Self::Output {
BoundedRange::new(self.start, self.end.min(other.to_inner().end))
}
}
impl<T, R> RangeIntersection<R, UpperBoundedSet<T>> for BoundedRange<T>
where
R: Rangetools<Inner = UpperBoundedSet<T>>,
T: Copy + Ord,
{
type Output = BoundedSet<T>;
fn intersection(self, other: R) -> Self::Output {
RangeIntersection::intersection(other.to_inner(), self)
}
}
impl<T, R> RangeIntersection<R, UnboundedRange> for BoundedRange<T>
where
R: Rangetools<Inner = UnboundedRange>,
T: Copy + Ord,
{
type Output = BoundedRange<T>;
fn intersection(self, other: R) -> Self::Output {
RangeIntersection::intersection(other.to_inner(), self)
}
}
impl<T, R> RangeIntersection<R, UnboundedSet<T>> for BoundedRange<T>
where
R: Rangetools<Inner = UnboundedSet<T>>,
T: Copy + Ord,
{
type Output = BoundedSet<T>;
fn intersection(self, other: R) -> Self::Output {
RangeIntersection::intersection(other.to_inner(), self)
}
}
impl<T, R> RangeIntersection<R, EmptyRange<T>> for BoundedRange<T>
where
R: Rangetools<Inner = EmptyRange<T>>,
T: Copy + Ord,
{
type Output = EmptyRange<T>;
fn intersection(self, other: R) -> Self::Output {
RangeIntersection::intersection(other.to_inner(), self)
}
}