diff options
Diffstat (limited to 'third_party/rust/indexmap/src/util.rs')
-rw-r--r-- | third_party/rust/indexmap/src/util.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/third_party/rust/indexmap/src/util.rs b/third_party/rust/indexmap/src/util.rs index a24dfafde7..377ff516f0 100644 --- a/third_party/rust/indexmap/src/util.rs +++ b/third_party/rust/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) +} |