Skip to content

Commit

Permalink
Update Range to match upstream (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb authored Nov 17, 2023
1 parent efe3457 commit 725b9a8
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<V: Ord> Range<V> {
.segments
.last()
.expect("if there is a first element, there must be a last element");
(bound_as_ref(start), bound_as_ref(&end.1))
(start.as_ref(), end.1.as_ref())
})
}

Expand Down Expand Up @@ -268,15 +268,6 @@ impl<V: Ord> Range<V> {
}
}

/// 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 @@ -311,7 +302,7 @@ impl<V: Ord + Clone> Range<V> {

(Included(i), Excluded(e)) | (Excluded(e), Included(i)) if i <= e => Excluded(e),
(Included(i), Excluded(e)) | (Excluded(e), Included(i)) if e < i => Included(i),
(s, Unbounded) | (Unbounded, s) => bound_as_ref(s),
(s, Unbounded) | (Unbounded, s) => s.as_ref(),
_ => unreachable!(),
}
.cloned();
Expand All @@ -321,7 +312,7 @@ impl<V: Ord + Clone> Range<V> {

(Included(i), Excluded(e)) | (Excluded(e), Included(i)) if i >= e => Excluded(e),
(Included(i), Excluded(e)) | (Excluded(e), Included(i)) if e > i => Included(i),
(s, Unbounded) | (Unbounded, s) => bound_as_ref(s),
(s, Unbounded) | (Unbounded, s) => s.as_ref(),
_ => unreachable!(),
}
.cloned();
Expand Down Expand Up @@ -377,7 +368,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 @@ -388,7 +379,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 725b9a8

Please sign in to comment.