range-compare 0.1.1

A crate to compare ranges
Documentation
  • Coverage
  • 47.37%
    18 out of 38 items documented13 out of 18 items with examples
  • Size
  • Source code size: 28.67 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Ruben2424/range-compare
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Ruben2424

range-compare

This crate provides a method to compare two ranges and get the overlapping parts of the ranges.

Examples

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,
}
);

Get the matching part of the original range

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());