| 1 |
use core::ops::{Bound, Range, RangeBounds}; |
| 2 |
|
| 3 |
pub(crate) fn third<A, B, C>(t: (A, B, C)) -> C { |
| 4 |
t.2 |
| 5 |
} |
| 6 |
|
| 7 |
pub(crate) fn simplify_range<R>(range: R, len: usize) -> Range<usize> |
| 8 |
where |
| 9 |
R: RangeBounds<usize>, |
| 10 |
{ |
| 11 |
let start = match range.start_bound() { |
| 12 |
Bound::Unbounded => 0, |
| 13 |
Bound::Included(&i) if i <= len => i, |
| 14 |
Bound::Excluded(&i) if i < len => i + 1, |
| 15 |
bound => panic!("range start {:?} should be <= length {}", bound, len), |
| 16 |
}; |
| 17 |
let end = match range.end_bound() { |
| 18 |
Bound::Unbounded => len, |
| 19 |
Bound::Excluded(&i) if i <= len => i, |
| 20 |
Bound::Included(&i) if i < len => i + 1, |
| 21 |
bound => panic!("range end {:?} should be <= length {}", bound, len), |
| 22 |
}; |
| 23 |
if start > end { |
| 24 |
panic!( |
| 25 |
"range start {:?} should be <= range end {:?}", |
| 26 |
range.start_bound(), |
| 27 |
range.end_bound() |
| 28 |
); |
| 29 |
} |
| 30 |
start..end |
| 31 |
} |