Module :: winterval
Integer interval adapter for both Range and RangeInclusive.
Let's assume you have a function which should accept Interval. But you don't want to limit caller of the function to either half-open interval core::ops::Range or closed one core::ops::RangeInclusive you want allow to use anyone of iterable interval. To make that work smoothly use IterableInterval. Both core::ops::Range and core::ops::RangeInclusive implement the trait, also it's possible to work with non-iterable intervals, like ( -Infinity .. +Infinity ).
Basic use-case.
use IterableInterval;
// Calling the function either with
// half-open interval `core::ops::Range`.
f1;
// Or closed one `core::ops::RangeInclusive`.
f1;
More flexibility
If you need more flexibility in defining intervals, you can convert a tuple of endpoints to an interval.
use ;
// Calling the function either with
// half-open interval `core::ops::Range`.
f1;
// Or closed one `core::ops::RangeInclusive`.
f1;
// Alternatively you construct your custom interval from a tuple.
f1;
f1;
// All the calls to the function `f1`` perform the same task,
// and the output is exactly identical.
Non-iterable intervals
You may also use the crate to specify non-iterable intervals. Non-iterable intervals have either one or several unbound endpoints. For example, interval core::ops::RangeFull has no bounds and represents the range from minus infinity to plus infinity.
use ;
// Iterable/bound interval from tuple.
f1;
// Non-iterable/unbound interval from tuple.
f1;
// Non-iterable/unbound interval from `core::ops::RangeFrom`.
f1;
// Non-iterable/unbound interval from `core::ops::RangeFull`
// what is ( -Infinity .. +Infinity ).
f1;
To add to your project
Try out from the repository