summaryrefslogtreecommitdiffstats
path: root/third_party/rust/indexmap/src/util.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
commit8dd16259287f58f9273002717ec4d27e97127719 (patch)
tree3863e62a53829a84037444beab3abd4ed9dfc7d0 /third_party/rust/indexmap/src/util.rs
parentReleasing progress-linux version 126.0.1-1~progress7.99u1. (diff)
downloadfirefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz
firefox-8dd16259287f58f9273002717ec4d27e97127719.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/indexmap/src/util.rs')
-rw-r--r--third_party/rust/indexmap/src/util.rs22
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)
+}