diff options
Diffstat (limited to 'vendor/indexmap/src/util.rs')
-rw-r--r-- | vendor/indexmap/src/util.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/vendor/indexmap/src/util.rs b/vendor/indexmap/src/util.rs index a24dfafde..377ff516f 100644 --- a/vendor/indexmap/src/util.rs +++ b/vendor/indexmap/src/util.rs @@ -29,3 +29,25 @@ where } start..end } + +pub(crate) fn try_simplify_range<R>(range: R, len: usize) -> Option<Range<usize>> +where + R: RangeBounds<usize>, +{ + let start = match range.start_bound() { + Bound::Unbounded => 0, + Bound::Included(&i) if i <= len => i, + Bound::Excluded(&i) if i < len => i + 1, + _ => return None, + }; + let end = match range.end_bound() { + Bound::Unbounded => len, + Bound::Excluded(&i) if i <= len => i, + Bound::Included(&i) if i < len => i + 1, + _ => return None, + }; + if start > end { + return None; + } + Some(start..end) +} |