Skip to content

Commit

Permalink
Initial divergences from upstream (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb authored and konstin committed Jan 3, 2024
1 parent 3b013da commit 04d1d1b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<V: Ord> Range<V> {
.segments
.last()
.expect("if there is a first element, there must be a last element");
(start.as_ref(), end.1.as_ref())
(bound_as_ref(start), bound_as_ref(&end.1))
})
}

Expand Down Expand Up @@ -321,6 +321,15 @@ fn within_bounds<V: PartialOrd>(v: &V, segment: &Interval<V>) -> Ordering {
Ordering::Greater
}

/// Implementation of [`Bound::as_ref`] which is currently marked as unstable.
fn bound_as_ref<V>(bound: &Bound<V>) -> Bound<&V> {
match bound {
Included(v) => Included(v),
Excluded(v) => Excluded(v),
Unbounded => Unbounded,
}
}

fn valid_segment<T: PartialOrd>(start: &Bound<T>, end: &Bound<T>) -> bool {
match (start, end) {
(Included(s), Included(e)) => s <= e,
Expand Down Expand Up @@ -545,7 +554,7 @@ impl<V: Display + Eq> Display for Range<V> {
} else {
for (idx, segment) in self.segments.iter().enumerate() {
if idx > 0 {
write!(f, " | ")?;
write!(f, ", ")?;
}
match segment {
(Unbounded, Unbounded) => write!(f, "*")?,
Expand All @@ -556,7 +565,7 @@ impl<V: Display + Eq> Display for Range<V> {
if v == b {
write!(f, "=={v}")?
} else {
write!(f, ">={v}, <={b}")?
write!(f, ">={v},<={b}")?
}
}
(Included(v), Excluded(b)) => write!(f, ">={v}, <{b}")?,
Expand Down

0 comments on commit 04d1d1b

Please sign in to comment.