pub trait RangeExt<T>: RangeBounds<T>where
T: Ord,{
// Required methods
fn normalize(
self,
start: impl Into<Option<T>>,
end: impl Into<Option<T>>
) -> Range<T>;
fn intersection<R>(self, other: R) -> Option<Range<T>>
where R: RangeExt<T>;
fn union<R>(self, other: R) -> Option<Range<T>>
where R: RangeExt<T>;
}
Expand description
Extension methods for working with various range types.
Required Methods§
sourcefn normalize(
self,
start: impl Into<Option<T>>,
end: impl Into<Option<T>>
) -> Range<T>
fn normalize( self, start: impl Into<Option<T>>, end: impl Into<Option<T>> ) -> Range<T>
Normalizes a range-like type to a canonical half-open Range
.
Parameters
self
: The range to normalize.start
: An optional fallback inclusive lower bound.end
: An optional fallback exclusive upper bound.
Returns
A Range
whose start and end values are the following, in order of
decreasing priority:
self.start()
, or if absent, thestart
parameter, or if it isNone
,0
.self.end()
, or if absent, theend
parameter, or if it isNone
, !0`.
sourcefn intersection<R>(self, other: R) -> Option<Range<T>>where
R: RangeExt<T>,
fn intersection<R>(self, other: R) -> Option<Range<T>>where R: RangeExt<T>,
Finds the intersection between two range-likes. The produced Range
spans only the elements common to both.
This returns None
if the ranges do not have an intersection (at least
one element present in both ranges).
Object Safety§
This trait is not object safe.