Trait wyz::range::RangeExt

source ·
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§

source

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

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

source

fn union<R>(self, other: R) -> Option<Range<T>>where R: RangeExt<T>,

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§

source§

impl<R> RangeExt<usize> for Rwhere R: RangeBounds<usize>,