Ranges v0.1.0

Source
The range types produced by the range operators.

Package: Rux

Each range operator builds one of these structs. A range with a start is iterable in a for loop; every range can slice a collection.

Definitions

struct Range<T> {            // a..b   — start up to, excluding, end
    start: T;
    end: T;
}

struct RangeInclusive<T> {   // a..=b  — start up to, including, end
    start: T;
    end: T;
}

struct RangeFrom<T> {        // a..    — start onward
    start: T;
}

struct RangeTo<T> {          // ..b    — up to, excluding, end
    end: T;
}

struct RangeToInclusive<T> { // ..=b   — up to, including, end
    end: T;
}

struct RangeFull {}          // ..     — the whole extent
TypeOperatorBoundsIterable
Range<T>a..bstart inclusive, end exclusive
RangeInclusive<T>a..=bboth inclusive
RangeFrom<T>a..start inclusive, unbounded end
RangeTo<T>..bunbounded start, end exclusive
RangeToInclusive<T>..=bunbounded start, end inclusive
RangeFull..the whole extent

The start-bearing ranges (Range, RangeInclusive, RangeFrom) can drive a for loop; the startless ones are for slicing only.

See also

  • Core — the package overview
  • Ranges — the language-reference treatment
  • Slice — what range-indexing a collection yields