1mod impl_range_bounds {
2 use crate::{Exclusive, Inclusive, LeftBounded, RightBounded};
3 use std::ops::{Bound, RangeBounds};
4
5 impl<T: PartialOrd> RangeBounds<T> for LeftBounded<T, Inclusive> {
6 fn start_bound(&self) -> Bound<&T> {
7 Bound::Included(&self.limit)
8 }
9 fn end_bound(&self) -> Bound<&T> {
10 Bound::Unbounded
11 }
12 }
13 impl<T: PartialOrd> RangeBounds<T> for LeftBounded<T, Exclusive> {
14 fn start_bound(&self) -> Bound<&T> {
15 Bound::Excluded(&self.limit)
16 }
17 fn end_bound(&self) -> Bound<&T> {
18 Bound::Unbounded
19 }
20 }
21 impl<T: PartialOrd> RangeBounds<T> for RightBounded<T, Inclusive> {
22 fn start_bound(&self) -> Bound<&T> {
23 Bound::Unbounded
24 }
25 fn end_bound(&self) -> Bound<&T> {
26 Bound::Included(&self.limit)
27 }
28 }
29 impl<T: PartialOrd> RangeBounds<T> for RightBounded<T, Exclusive> {
30 fn start_bound(&self) -> Bound<&T> {
31 Bound::Unbounded
32 }
33 fn end_bound(&self) -> Bound<&T> {
34 Bound::Excluded(&self.limit)
35 }
36 }
37}
38
39mod converters {
40 use crate::{Exclusive, Inclusive, Interval, IntervalIsEmpty};
41
42 impl<T: PartialOrd> TryFrom<std::ops::Range<T>> for Interval<T, Inclusive, Exclusive> {
51 type Error = IntervalIsEmpty;
52 fn try_from(r: std::ops::Range<T>) -> Result<Self, Self::Error> {
53 Self::try_new(r.start.into(), r.end.into()).ok_or(IntervalIsEmpty)
54 }
55 }
56
57 impl<T: PartialOrd> TryFrom<std::ops::RangeInclusive<T>> for Interval<T, Inclusive> {
66 type Error = IntervalIsEmpty;
67 fn try_from(r: std::ops::RangeInclusive<T>) -> Result<Self, Self::Error> {
68 let (left, right) = r.into_inner();
69 Self::try_new(left.into(), right.into()).ok_or(IntervalIsEmpty)
70 }
71 }
72
73 impl<T> From<Interval<T, Inclusive, Exclusive>> for std::ops::Range<T> {
81 fn from(i: Interval<T, Inclusive, Exclusive>) -> Self {
82 i.left.0.limit..i.right.0.limit
83 }
84 }
85
86 impl<T> From<Interval<T, Inclusive, Inclusive>> for std::ops::RangeInclusive<T> {
94 fn from(i: Interval<T, Inclusive, Inclusive>) -> Self {
95 i.left.0.limit..=i.right.0.limit
96 }
97 }
98}