#range #compare #overlapping #parts #original #included #range-cmp-result

range-compare

一个用于比较范围和获取范围重叠部分的库

2 个版本

0.1.1 2023 年 12 月 19 日
0.1.0 2023 年 12 月 19 日

7#overlapping

MIT 许可证

28KB
499

range-compare

该库提供了一种比较两个范围并获取范围重叠部分的方法。

示例

use range_compare::{RangeExt, RangeCmpResult};

// create two ranges
let range1 = 2..10;
let range2 = 5..15;

// compare the original range1 with the other range2
// safe the [RangeCmpResult] of the comparison in a variable
let result = range1.compare(&range2);

assert_eq!(
   result,
   RangeCmpResult::EndIncluded {
       other_after: 10..15,
       original_part_which_is_not_included: 2..5,
       overlapping_part: 5..10,
}
);

获取原始范围匹配的部分

use range_compare::{RangeExt, RangeCmpResult};

// create two ranges
let range1 = 29..40;
let range2 = 35..70;

// compare the original range1 with the other range2
// safe the [RangeCmpResult] of the comparison in a variable
let result = range1.compare(&range2);

// get the matching part of the original range
let matching_part = result.get_matching_part();

assert_eq!(matching_part, Some(35..40).as_ref());

无运行时依赖