range-cmp 0.1.3

Trait that allows comparing a value to a range of values
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented3 out of 5 items with examples
  • Size
  • Source code size: 27.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.64 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • qsantos adriendellagaspera romain-akvize

range_cmp

This Rust crate provides the RangeComparable trait on all types that implement Ord. This traits exposes a range_cmp associated method that allows comparing a value with a range of values:

use range_cmp::{RangeComparable, RangeOrdering};
assert_eq!(15.range_cmp(20..30), RangeOrdering::Below);
assert_eq!(25.range_cmp(20..30), RangeOrdering::Inside);
assert_eq!(35.range_cmp(20..30), RangeOrdering::Above);

Empty ranges handling

This crate does not strictly handle empty ranges, which are not mathematically comparable. In this case, range_cmp will show different behavior depending on the representation of the empty range. For instance:

assert_eq!(30.range_cmp(45..35), RangeOrdering::Below);
assert_eq!(30.range_cmp(25..15), RangeOrdering::Above);
assert_eq!(0.range_cmp(0..0), RangeOrdering::Above);