3 releases (breaking)

0.3.0 Sep 5, 2023
0.2.0 Jul 28, 2023
0.1.3 Jun 6, 2019

#1000 in Rust patterns

Download history 56/week @ 2024-11-16 84/week @ 2024-11-23 87/week @ 2024-11-30 155/week @ 2024-12-07 99/week @ 2024-12-14 44/week @ 2024-12-21 66/week @ 2024-12-28 122/week @ 2025-01-04 147/week @ 2025-01-11 151/week @ 2025-01-18 126/week @ 2025-01-25 122/week @ 2025-02-01 140/week @ 2025-02-08 120/week @ 2025-02-15 161/week @ 2025-02-22 140/week @ 2025-03-01

579 downloads per month
Used in salvation

MIT license

26KB
482 lines

Range-Ext

Range-Ext is a Rust library to handle range intersections. It provides a set of types and methods to determine whether and how two numeric ranges intersect.

Features

  • Intersection Enumeration: A simple enumeration helps to identify the type of intersection occurring between ranges. Options include: Empty, Overlap, and Full.
  • Extended Intersection Enumeration: An extended enumeration introduces additional, more specific types of intersection for ranges. It includes Bellow, BellowOverlap, Within, Same, Over, AboveOverlap, Above.
  • Intersection Trait: A trait that can be implemented on ranges to determine the kind of intersection with another range.

Usage

To use Range-Ext in your Rust program, add it to your Cargo.toml file:

use range_ext::{IntersectionExt, Intersect};

let range1 = 3..10;
let range2 = 5..8;

let intersection = range1.intersect(&range2);

Issue: I think there is a problem with intersecting Range, if either of the ranges have no ascending start to end. To make it work I have assumed I can reverse if they are descending, but that is causing the other to becaome RangeToInclusive, and that is not yet implemented. So dont have any descending ranges for now.

TODO: There is still missing RangeToInclusive at the moment.

No runtime deps