Coverage Report

Created: 2025-12-28 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/indexmap-2.7.1/src/util.rs
Line
Count
Source
1
use core::ops::{Bound, Range, RangeBounds};
2
3
0
pub(crate) fn third<A, B, C>(t: (A, B, C)) -> C {
4
0
    t.2
5
0
}
Unexecuted instantiation: indexmap::util::third::<usize, serde_yaml::value::Value, serde_yaml::value::Value>
Unexecuted instantiation: indexmap::util::third::<usize, h2::frame::stream_id::StreamId, h2::proto::streams::store::SlabIndex>
6
7
#[track_caller]
8
pub(crate) fn simplify_range<R>(range: R, len: usize) -> Range<usize>
9
where
10
    R: RangeBounds<usize>,
11
{
12
    let start = match range.start_bound() {
13
        Bound::Unbounded => 0,
14
        Bound::Included(&i) if i <= len => i,
15
        Bound::Excluded(&i) if i < len => i + 1,
16
        Bound::Included(i) | Bound::Excluded(i) => {
17
            panic!("range start index {i} out of range for slice of length {len}")
18
        }
19
    };
20
    let end = match range.end_bound() {
21
        Bound::Unbounded => len,
22
        Bound::Excluded(&i) if i <= len => i,
23
        Bound::Included(&i) if i < len => i + 1,
24
        Bound::Included(i) | Bound::Excluded(i) => {
25
            panic!("range end index {i} out of range for slice of length {len}")
26
        }
27
    };
28
    if start > end {
29
        panic!(
30
            "range start index {:?} should be <= range end index {:?}",
31
            range.start_bound(),
32
            range.end_bound()
33
        );
34
    }
35
    start..end
36
}
37
38
pub(crate) fn try_simplify_range<R>(range: R, len: usize) -> Option<Range<usize>>
39
where
40
    R: RangeBounds<usize>,
41
{
42
    let start = match range.start_bound() {
43
        Bound::Unbounded => 0,
44
        Bound::Included(&i) if i <= len => i,
45
        Bound::Excluded(&i) if i < len => i + 1,
46
        _ => return None,
47
    };
48
    let end = match range.end_bound() {
49
        Bound::Unbounded => len,
50
        Bound::Excluded(&i) if i <= len => i,
51
        Bound::Included(&i) if i < len => i + 1,
52
        _ => return None,
53
    };
54
    if start > end {
55
        return None;
56
    }
57
    Some(start..end)
58
}