range_bound_cmp
Range Bound Cmp
Comparison operations between primitive Bound values.
Usage
range_bound_cmp aims to simplify set operations on primitive ranges by providing
lower and upper bound specific implementations of PartialEq, Eq, PartialOrd and Ord.
This allows for comparison of values rather than variants. Take for example the following
assertions:
assert!;
// The above is `false` for `LowerBound` but `true` for `UpperBound`.
assert!;
assert!;
// Therefore we can make more assertions for the entire range.
assert!;
assert!;
Passing a range into OrdRange will wrap the bounds for comparison operations.
Use the RangeBound implementation on OrdRange, or call take to return the
unwrapped bounds for operations such as slicing into an array. Range bound assertions
are particularly useful in the development of range set algorithms. Take for example this
naive implementation of intersection below:
// Our return type.
pub type TupleRange<T> = ;
/// Get the range of elements in both sets `a` and `b`.
assert_eq!;
Lower and Upper bound conversion
Conversion between LowerBound and UpperBound using TryFrom or TryInto
has the following behaviour:
Boundvariant is always maintained.LowerBound::Included(5)will be converted toUpperBound::Included(5)whileLowerBound::Excluded(4)will be converted toUpperBound::Excluded(6).Bound::Unboundedconversion is always an error. The lower bound of..10is not equal to the upper bound of0...
License: MIT OR Apache-2.0