| Crates.io | rust_intervals |
| lib.rs | rust_intervals |
| version | 1.0.0 |
| created_at | 2024-10-13 17:12:34.809818+00 |
| updated_at | 2025-03-01 16:20:24.259874+00 |
| description | Intervals arithmetic with any combination of open, closed or infinite bounds, along with operations like intersection, convex hull, union, difference,... |
| homepage | |
| repository | https://github.com/briot/rust_intervals |
| max_upload_size | |
| id | 1407485 |
| size | 186,953 |
This package provides various functions to deal with intervals (aka ranges) of values.
It provides the following features:
contains(): whether the interval contains a specific valuecontains_interval(): whether the interval fully includes another
interval.is_empty(): does the interval contain any value ?equivalent(): do two intervals contain the same set of values ?strictly_left_of(), left_of(), right_of(), strictly_right_of():
relative positions of two intervalsconvex_hull(): smallest interval that contains two othersdifference(): all values in one interval but not in anothersymmetric_difference(): all values in either interval, but not in
bothintersection(): all values in both intervalsbetween(): all values between two intervalscontiguous(): whether two intervals are contiguous, with no values
between themunion(): union of two contiguous intervals&, |, ^, ==)serdeno_stdDefault, Clone, Copy, Display,
Debug, Eq, PartialEq, Ord, PartialOrd, Hash,
From<String>, From<Interval> -> String and FromStr
depending on what your type provides. See examples below on how to
convert to and from a string.a..b, a..=b and so onIterator, DoubleEndedIterator, ExactSizeIterator
and IntoIteratorBorrow in parameters to make interface more convenient use rust_intervals::{interval, Interval};
let intv1 = Interval::new_closed_open(1, 10);
let value = 5;
assert!(intv1.contains(&value));
let intv2 = interval!(5, 8, "()");
assert!(intv1.contains_interval(&intv2));
let _ = intv1.convex_hull(&intv2);
An interval can be converted to a string using the various standard Rust approaches:
use rust_intervals::{interval, Interval};
let intv1 = Interval::new_closed_open(1, 10);
let s = format!("{}", intv1); // using the Display trait
let s = intv1.to_string(); // using the ToString trait (via Display)
let s = String::from(intv1); // using From<Interval<T>>->String trait
let s: String = intv1.into(); // using the Into<String> trait
let s = "[1, 4]";
let intv = Interval::<u32>::from(s); // using From<String> trait
let intv: Interval<u32> = s.into(); // using Into<Interval<T>> trait
let intv: Interval<u32> = s.parse()?; // using FromStr trait (may fail)
This library includes extensive testing (cargo make test-all),
including support for MC/DC coverage (cargo make cov, reaching a total of
95.16%, where the remaining uncovered code all seem to be unreachable code).
We also work fuzzing tests (cargo make fuzz) and random mutations on the
code to detect missing tests (cargo make mutants).
std::ops::Range are the Rust built-in ranges. They only provide
a contains() function, do not provide Copy and do not provide all the
kinds of bounds.
Extent [https://docs.rs/extent/latest/extent/] only provide closed-closed
intervals. They also do not provide all the operations like between(),
convex_hull() and so forth. In exchange, they do not require extra flags
in the struct, which makes them slightly smaller.
The following features are planned.