| 1 | use std::ops::Bound; |
| 2 | |
| 3 | /// Converts a range bound to its indexes. |
| 4 | pub(super) fn bounds_to_usize( |
| 5 | left: Bound<&usize>, |
| 6 | right: Bound<&usize>, |
| 7 | count_elements: usize, |
| 8 | ) -> (usize, usize) { |
| 9 | match (left, right) { |
| 10 | (Bound::Included(x: &usize), Bound::Included(y: &usize)) => (*x, y + 1), |
| 11 | (Bound::Included(x: &usize), Bound::Excluded(y: &usize)) => (*x, *y), |
| 12 | (Bound::Included(x: &usize), Bound::Unbounded) => (*x, count_elements), |
| 13 | (Bound::Unbounded, Bound::Unbounded) => (0, count_elements), |
| 14 | (Bound::Unbounded, Bound::Included(y: &usize)) => (0, y + 1), |
| 15 | (Bound::Unbounded, Bound::Excluded(y: &usize)) => (0, *y), |
| 16 | (Bound::Excluded(_), Bound::Unbounded) |
| 17 | | (Bound::Excluded(_), Bound::Included(_)) |
| 18 | | (Bound::Excluded(_), Bound::Excluded(_)) => { |
| 19 | unreachable!("A start bound can't be excluded" ) |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | |