Debian Codegraph @

debian/rust-vendor/rayon/src/math.rs

raw
1 use std::ops::{Bound, Range, RangeBounds};
2
3 /// Normalize arbitrary `RangeBounds` to a `Range`
4 pub(super) fn simplify_range(range: impl RangeBounds<usize>, len: usize) -> Range<usize> {
5 let start = match range.start_bound() {
6 Bound::Unbounded => 0,
7 Bound::Included(&i) if i <= len => i,
8 Bound::Excluded(&i) if i < len => i + 1,
9 bound => panic!("range start {bound:?} should be <= length {len}"),
10 };
11 let end = match range.end_bound() {
12 Bound::Unbounded => len,
13 Bound::Excluded(&i) if i <= len => i,
14 Bound::Included(&i) if i < len => i + 1,
15 bound => panic!("range end {bound:?} should be <= length {len}"),
16 };
17 if start > end {
18 panic!(
19 "range start {:?} should be <= range end {:?}",
20 range.start_bound(),
21 range.end_bound()
22 );
23 }
24 start..end
25 }