Coverage Report

Created: 2024-10-16 07:58

/rust/registry/src/index.crates.io-6f17d22bba15001f/indexmap-2.2.6/src/util.rs
Line
Count
Source (jump to first uncovered line)
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
}
6
7
pub(crate) fn simplify_range<R>(range: R, len: usize) -> Range<usize>
8
where
9
    R: RangeBounds<usize>,
10
{
11
    let start = match range.start_bound() {
12
        Bound::Unbounded => 0,
13
        Bound::Included(&i) if i <= len => i,
14
        Bound::Excluded(&i) if i < len => i + 1,
15
        bound => panic!("range start {:?} should be <= length {}", bound, len),
16
    };
17
    let end = match range.end_bound() {
18
        Bound::Unbounded => len,
19
        Bound::Excluded(&i) if i <= len => i,
20
        Bound::Included(&i) if i < len => i + 1,
21
        bound => panic!("range end {:?} should be <= length {}", bound, len),
22
    };
23
    if start > end {
24
        panic!(
25
            "range start {:?} should be <= range end {:?}",
26
            range.start_bound(),
27
            range.end_bound()
28
        );
29
    }
30
    start..end
31
}
32
33
pub(crate) fn try_simplify_range<R>(range: R, len: usize) -> Option<Range<usize>>
34
where
35
    R: RangeBounds<usize>,
36
{
37
    let start = match range.start_bound() {
38
        Bound::Unbounded => 0,
39
        Bound::Included(&i) if i <= len => i,
40
        Bound::Excluded(&i) if i < len => i + 1,
41
        _ => return None,
42
    };
43
    let end = match range.end_bound() {
44
        Bound::Unbounded => len,
45
        Bound::Excluded(&i) if i <= len => i,
46
        Bound::Included(&i) if i < len => i + 1,
47
        _ => return None,
48
    };
49
    if start > end {
50
        return None;
51
    }
52
    Some(start..end)
53
}