Trait wyz::range::RangeExt

source ·
pub trait RangeExt<T>: RangeBounds<T>where
    T: Ord,
{ 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

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, the start parameter, or if it is None, 0.
  • self.end(), or if absent, the end parameter, or if it is None, !0`.

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).

Finds the union between two range-likes. The produced Range spans all elements present in at least one of them.

This returns None if the ranges do not have an intersection (at least one element present in both ranges).

Implementors