Skip to content

Trait that allows comparing a value to a range of values.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

Akvize/range-cmp

Repository files navigation

range_cmp

Crates.io MIT licensed Apache licensed Build Status

Docs

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

use range_cmp::{RangeComparable, RangeOrdering};
assert_eq!(15.rcmp(20..30), RangeOrdering::Below);
assert_eq!(25.rcmp(20..30), RangeOrdering::Inside);
assert_eq!(35.rcmp(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);

About

Trait that allows comparing a value to a range of values.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published