Skip to content

Commit acfbe99

Browse files
authored
refactor: as_ref is stable as of 1.65 and "," is ambiguous (#147)
1 parent fe309ff commit acfbe99

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/range.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<V: Ord> Range<V> {
195195
.segments
196196
.last()
197197
.expect("if there is a first element, there must be a last element");
198-
(bound_as_ref(start), bound_as_ref(&end.1))
198+
(start.as_ref(), end.1.as_ref())
199199
})
200200
}
201201

@@ -264,15 +264,6 @@ impl<V: Ord> Range<V> {
264264
}
265265
}
266266

267-
/// Implementation of [`Bound::as_ref`] which is currently marked as unstable.
268-
fn bound_as_ref<V>(bound: &Bound<V>) -> Bound<&V> {
269-
match bound {
270-
Included(v) => Included(v),
271-
Excluded(v) => Excluded(v),
272-
Unbounded => Unbounded,
273-
}
274-
}
275-
276267
fn valid_segment<T: PartialOrd>(start: &Bound<T>, end: &Bound<T>) -> bool {
277268
match (start, end) {
278269
(Included(s), Included(e)) => s <= e,
@@ -307,7 +298,7 @@ impl<V: Ord + Clone> Range<V> {
307298

308299
(Included(i), Excluded(e)) | (Excluded(e), Included(i)) if i <= e => Excluded(e),
309300
(Included(i), Excluded(e)) | (Excluded(e), Included(i)) if e < i => Included(i),
310-
(s, Unbounded) | (Unbounded, s) => bound_as_ref(s),
301+
(s, Unbounded) | (Unbounded, s) => s.as_ref(),
311302
_ => unreachable!(),
312303
}
313304
.cloned();
@@ -317,7 +308,7 @@ impl<V: Ord + Clone> Range<V> {
317308

318309
(Included(i), Excluded(e)) | (Excluded(e), Included(i)) if i >= e => Excluded(e),
319310
(Included(i), Excluded(e)) | (Excluded(e), Included(i)) if e > i => Included(i),
320-
(s, Unbounded) | (Unbounded, s) => bound_as_ref(s),
311+
(s, Unbounded) | (Unbounded, s) => s.as_ref(),
321312
_ => unreachable!(),
322313
}
323314
.cloned();
@@ -373,7 +364,7 @@ impl<V: Display + Eq> Display for Range<V> {
373364
} else {
374365
for (idx, segment) in self.segments.iter().enumerate() {
375366
if idx > 0 {
376-
write!(f, ", ")?;
367+
write!(f, " | ")?;
377368
}
378369
match segment {
379370
(Unbounded, Unbounded) => write!(f, "*")?,
@@ -384,7 +375,7 @@ impl<V: Display + Eq> Display for Range<V> {
384375
if v == b {
385376
write!(f, "{v}")?
386377
} else {
387-
write!(f, ">={v},<={b}")?
378+
write!(f, ">={v}, <={b}")?
388379
}
389380
}
390381
(Included(v), Excluded(b)) => write!(f, ">={v}, <{b}")?,

0 commit comments

Comments
 (0)