rangetools/implementations/intersection/
upper_bounded_range.rs

1use crate::{
2    BoundedRange, BoundedSet, EmptyRange, LowerBoundedRange, LowerBoundedSet, RangeIntersection,
3    Rangetools, UnboundedRange, UnboundedSet, UpperBoundedRange, UpperBoundedSet,
4};
5
6impl<T, R> RangeIntersection<R, BoundedRange<T>> for UpperBoundedRange<T>
7where
8    R: Rangetools<Inner = BoundedRange<T>>,
9    T: Copy + Ord,
10{
11    type Output = BoundedRange<T>;
12    fn intersection(self, other: R) -> Self::Output {
13        RangeIntersection::intersection(other.to_inner(), self)
14    }
15}
16
17impl<T, R> RangeIntersection<R, BoundedSet<T>> for UpperBoundedRange<T>
18where
19    R: Rangetools<Inner = BoundedSet<T>>,
20    T: Copy + Ord,
21{
22    type Output = BoundedSet<T>;
23    fn intersection(self, other: R) -> Self::Output {
24        RangeIntersection::intersection(other.to_inner(), self)
25    }
26}
27
28impl<T, R> RangeIntersection<R, LowerBoundedRange<T>> for UpperBoundedRange<T>
29where
30    R: Rangetools<Inner = LowerBoundedRange<T>>,
31    T: Copy + Ord,
32{
33    type Output = BoundedRange<T>;
34    fn intersection(self, other: R) -> Self::Output {
35        RangeIntersection::intersection(other.to_inner(), self)
36    }
37}
38
39impl<T, R> RangeIntersection<R, LowerBoundedSet<T>> for UpperBoundedRange<T>
40where
41    R: Rangetools<Inner = LowerBoundedSet<T>>,
42    T: Copy + Ord,
43{
44    type Output = BoundedSet<T>;
45    fn intersection(self, other: R) -> Self::Output {
46        RangeIntersection::intersection(other.to_inner(), self)
47    }
48}
49
50impl<T, R> RangeIntersection<R, UpperBoundedRange<T>> for UpperBoundedRange<T>
51where
52    R: Rangetools<Inner = UpperBoundedRange<T>>,
53    T: Copy + Ord,
54{
55    type Output = UpperBoundedRange<T>;
56    fn intersection(self, other: R) -> Self::Output {
57        UpperBoundedRange::new(self.end.min(other.to_inner().end))
58    }
59}
60
61impl<T, R> RangeIntersection<R, UpperBoundedSet<T>> for UpperBoundedRange<T>
62where
63    R: Rangetools<Inner = UpperBoundedSet<T>>,
64    T: Copy + Ord,
65{
66    type Output = UpperBoundedSet<T>;
67    fn intersection(self, other: R) -> Self::Output {
68        RangeIntersection::intersection(other.to_inner(), self)
69    }
70}
71
72impl<T, R> RangeIntersection<R, UnboundedRange> for UpperBoundedRange<T>
73where
74    R: Rangetools<Inner = UnboundedRange>,
75{
76    type Output = UpperBoundedRange<T>;
77    fn intersection(self, other: R) -> Self::Output {
78        RangeIntersection::intersection(other.to_inner(), self)
79    }
80}
81
82impl<T, R> RangeIntersection<R, UnboundedSet<T>> for UpperBoundedRange<T>
83where
84    R: Rangetools<Inner = UnboundedSet<T>>,
85    T: Copy + Ord,
86{
87    type Output = UpperBoundedSet<T>;
88    fn intersection(self, other: R) -> Self::Output {
89        RangeIntersection::intersection(other.to_inner(), self)
90    }
91}
92
93impl<T, R> RangeIntersection<R, EmptyRange<T>> for UpperBoundedRange<T>
94where
95    R: Rangetools<Inner = EmptyRange<T>>,
96    T: Copy + Ord,
97{
98    type Output = EmptyRange<T>;
99    fn intersection(self, other: R) -> Self::Output {
100        other.to_inner()
101    }
102}