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: usize = match range.start_bound() { |
12 | Bound::Unbounded => 0, |
13 | Bound::Included(&i: usize) if i <= len => i, |
14 | Bound::Excluded(&i: usize) if i < len => i + 1, |
15 | bound: Bound<&usize> => panic!("range start {:?} should be <= length {}" , bound, len), |
16 | }; |
17 | let end: usize = match range.end_bound() { |
18 | Bound::Unbounded => len, |
19 | Bound::Excluded(&i: usize) if i <= len => i, |
20 | Bound::Included(&i: usize) if i < len => i + 1, |
21 | bound: Bound<&usize> => 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 | } |
32 | |