wyz::range

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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