Expand description
Extra methods for the standard library Range types:
std::ops::Rangestd::ops::RangeFromstd::ops::RangeFullstd::ops::RangeInclusivestd::ops::RangeTostd::ops::RangeToInclusive
To extend these types with the methods in this crate, import the
Rangetools trait:
use rangetools::Rangetools;This provides new methods on all of the above types, as well as any types introduced in this crate to manage the outputs of such methods.
use rangetools::Rangetools;
let i = (0..5).intersection(3..);
assert!(i.contains(4));
let i2 = (0..5).intersection(5..10);
assert!(i2.is_empty());Wherever possible (when the result is lower-bounded), the resulting
types of these operations implement IntoIterator so that more operations
can be performed on them.
use rangetools::Rangetools;
let u1 = (1..3).union(5..7);
assert_eq!(u1.into_iter().collect::<Vec<_>>(), vec![1, 2, 5, 6]);
let u2 = (1..3).union(10..);
assert_eq!(u2.into_iter().take(5).collect::<Vec<_>>(), vec![1, 2, 10, 11, 12]);ⓘ
let c = (1..3).complement();
let i = c.into_iter(); // Compiler error! The result has no lower bound
// and thus cannot be iterated over.§Crate features
serde - When enabled, derives [serde]’s Serialize and Deserialize traits for
all of the types introduced in this crate.
Structs§
- Bounded
Range - A range bounded both below and above (either inclusive or exclusive).
- Bounded
Range Iter - An iterator over the values contained by a
BoundedRange. - Bounded
Set - A set of ranges ultimately bounded both below and above.
- Bounded
SetIter - An iterator over the values contained by a
BoundedSet. - Empty
Range - A range with no elements.
- Lower
Bound - Lower bound of a range.
- Lower
Bounded Range - A range only bounded below (either inclusive or exclusive).
- Lower
Bounded Range Iter - An iterator over the values contained by a
LowerBoundedRange. - Lower
Bounded Set - A set of ranges with a finite lower bound but no upper bound.
- Lower
Bounded SetIter - An iterator over the values contained by a
LowerBoundedSet. - Piecewise
Unbounded Set - A set of ranges with ultimately no upper or lower bound.
- Unbounded
Range - A range with no upper or lower bound.
- Upper
Bound - Upper bound of a range.
- Upper
Bounded Range - A range only bounded above (either inclusive or exclusive).
- Upper
Bounded Set - A set of ranges with a finite upper bound but no lower bound.
Enums§
- Bound
- Endpoints of a closed range.
- Unbounded
Set - A set of ranges ultimately with no upper or lower bound.
Traits§
- Range
Complement - Helper trait for performing range complement.
- Range
Intersection - Helper trait for performing range intersection.
- Range
Union - Helper trait for performing range unions.
- Rangetools
- Extends the standard library Range types with extra functionality.
- Step
- Types are required to implement this trait for ranges of that type to be iterated through.