TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
..= operator in Rust is the inclusive range operator. It constructs a range that spans from a starting bound up to, and strictly including, an ending bound.
Depending on the presence of the starting bound, the operator evaluates to one of two distinct struct types within the std::ops module:
start..=end: Evaluates tostd::ops::RangeInclusive<Idx>...=end: Evaluates tostd::ops::RangeToInclusive<Idx>.
Type Requirements and Trait Implementations
Iterator:RangeInclusive<Idx>implements theIteratortrait if the underlying typeIdximplements thestd::iter::Steptrait (which is implemented for primitive integers andchar).RangeToInclusive<Idx>does not implementIteratorbecause it lacks a defined starting point.SliceIndex: BothRangeInclusiveandRangeToInclusiveimplement thestd::slice::SliceIndextrait, allowing them to be passed directly to indexing operations to yield sub-slices.Contains: Both types implement theRangeBounds<Idx>trait, providing thecontainsmethod to check if a specific value falls within the inclusive bounds.
Internal Mechanics and Overflow Safety
Unlike the exclusive range operator (..), RangeInclusive must safely handle iteration up to the absolute maximum value of a given type (e.g., 255 for u8).
If an exclusive range iterates to u8::MAX, the loop terminates before yielding it. An inclusive range must yield u8::MAX and then terminate. To prevent integer overflow (which would panic in debug mode or wrap in release mode) when attempting to increment past the maximum value, RangeInclusive maintains an internal boolean flag to track iterator exhaustion. Consequently, the memory footprint of RangeInclusive is slightly larger than that of std::ops::Range.
Pattern Matching Syntax
Beyond expression evaluation, the compiler parses..= as a distinct token for pattern matching. When used in a match arm, it does not instantiate a RangeInclusive struct at runtime; instead, it generates a direct comparison branch at the compiler level.
Master Rust with Deep Grasping Methodology!Learn More





