pub struct RangeData {
pub start: i64,
pub end: i64,
pub step: i64,
pub inclusive: bool,
}Expand description
Range value carrier — an inclusive-or-exclusive integer interval with
step. Built by MakeRange from the surface syntax start..end (exclusive)
and start..=end (inclusive); produced as a typed Arc<RangeData> slot
labeled NativeKind::Ptr(HeapKind::Range).
Distinct from IteratorState. Range is a value with identity
(r.start, r.end, r.contains(x), print(r) -> 0..10) — an
IteratorState is a stateful pipeline with a cursor. The .iter()
receiver method on Range converts a RangeData into a fresh
IteratorState with IteratorSource::Range { start, end_exclusive, step }, where end_exclusive is end + step for inclusive ranges
(so 0..=10 step 1 produces values 0..11). IteratorSource::Range
already models the post-conversion shape (W13-iterator-state, ADR-006
§2.7.16); RangeData is the pre-iter receiver value.
Bounds storage. Today only i64 integer ranges are representable.
The Option<i64> shape used by the deleted pre-bulldozer Range payload
(open ranges ..end, start.., ..) is deliberately NOT modeled here:
the surface syntax for open ranges still compiles via op_make_range
pushing a PushNull for the missing side, but the SURFACE handler
rejects them per the playbook’s surface-and-stop discipline (open
ranges need an iterator-tier semantic for for i in 0.. infinite
loops which is its own ADR follow-up). step is always positive —
matching the pre-strict-typing 0..n Rust-shape semantics.
Fields§
§start: i64Inclusive lower bound.
end: i64Upper bound. When inclusive == true, the value end itself is
reachable; when inclusive == false, end is exclusive (the
surface-syntax start..end shape).
step: i64Per-iteration increment. Always positive; defaults to 1 from the
MakeRange opcode (the surface syntax has no step suffix today).
inclusive: boolWhether the upper bound is reachable (start..=end shape).
Implementations§
Source§impl RangeData
impl RangeData
Sourcepub fn new(start: i64, end: i64, step: i64, inclusive: bool) -> Self
pub fn new(start: i64, end: i64, step: i64, inclusive: bool) -> Self
Construct a fresh range with the given bounds and step.
Sourcepub fn exclusive(start: i64, end: i64) -> Self
pub fn exclusive(start: i64, end: i64) -> Self
Construct an exclusive range start..end with step 1 (matching
the surface-syntax 0..n shape).
Sourcepub fn inclusive(start: i64, end: i64) -> Self
pub fn inclusive(start: i64, end: i64) -> Self
Construct an inclusive range start..=end with step 1.
Sourcepub fn end_exclusive(&self) -> i64
pub fn end_exclusive(&self) -> i64
Effective exclusive end — end + step for inclusive ranges,
end for exclusive ranges. Matches the upper bound used by
IteratorSource::Range’s end field (which is exclusive by
W13-iterator-state’s contract).
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Element count. Mirrors IteratorSource::Range::len so a range
and its post-.iter() IteratorState report the same count. For
non-positive step or an empty interval, returns 0.
Sourcepub fn contains(&self, value: i64) -> bool
pub fn contains(&self, value: i64) -> bool
Whether value falls within the range. The check is bound-aware
(inclusive vs exclusive end) but does NOT enforce step alignment
— (0..10).contains(5) is true regardless of step. This matches
the pre-bulldozer surface-syntax shape: range.contains is a
bound test, not a “would .iter() yield this exact value” probe.
Sourcepub fn to_vec_i64(&self) -> Vec<i64>
pub fn to_vec_i64(&self) -> Vec<i64>
Materialize the range into a Vec<i64> of every yielded value
(mirror of .iter().collect() for the pre-bulldozer
range.toArray() method shape). Empty range -> empty vec.