> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust Range Pattern

A range pattern is a pattern-matching construct that evaluates whether a target value falls within a contiguous sequence of scalar values defined by a lower and upper bound. It is evaluated at runtime as a set of boolean boundary checks rather than a discrete sequence of equality comparisons.

## Syntax and Bounds

Range patterns utilize Rust's standard range operators to define boundaries. Stable Rust fully supports both inclusive and exclusive ranges, as well as half-open bounds.

```rust theme={"dark"}
const MIN_VAL: i32 = 10;
const MAX_VAL: i32 = 20;
let target_value = 15;

match target_value {
    // Half-open exclusive upper bound (matches < -10)
    ..-10 => {} 

    // Half-open inclusive upper bound (matches <= 0)
    ..=0 => {}

    // Closed exclusive range (matches MIN_VAL through MAX_VAL - 1)
    MIN_VAL..MAX_VAL => {}

    // Closed inclusive range using literals (matches 30 through 39)
    30..=39 => {}

    // Half-open lower bound (matches >= 50)
    50.. => {}
    
    _ => {}
}
```

## Technical Constraints

**Constant Bounds**
Range pattern bounds must be constant expressions. This strictly requires the use of literals (e.g., `42`, `'a'`) or explicitly declared `const` variables. Dynamically evaluated runtime variables (standard local variables) cannot be used as bounds; attempting to do so will result in a compile-time error regarding non-constant values in patterns (such as `error[E0158]` or `error[E0435]`).

**Type Restrictions**
Range patterns are strictly limited to scalar types that possess a defined, contiguous order at compile time. This restricts their usage to:

* Integer types (`i8`, `u8`, `i32`, `usize`, etc.)
* Character types (`char`)
* Byte literals (`b'a'`)

*Note: Floating-point types (`f32`, `f64`) are not supported in range patterns due to the ambiguity of floating-point representation and `NaN` comparisons.*

**Exhaustiveness Checking**
When utilized within a `match` expression, range patterns do not inherently satisfy the compiler's exhaustiveness requirements unless the bounds explicitly cover the absolute minimum and maximum values of the target type (e.g., `u8::MIN..=u8::MAX`). In almost all scenarios, a wildcard pattern (`_`) or binding is required to handle values outside the specified ranges.

**Evaluation Order and Shadowing**
Like all patterns in Rust, range patterns are evaluated strictly top-to-bottom. If a range pattern overlaps with a preceding pattern, the first matching arm is executed. The Rust compiler's pattern-matching analysis pass will emit an `unreachable_pattern` warning if a range pattern is entirely subsumed by a previous arm.

```rust theme={"dark"}
let value = 7;

match value {
    0..=10 => { /* Evaluated first: value >= 0 && value <= 10 */ }
    5..=15 => { /* Evaluated second: value >= 5 && value <= 15 */ } // 5..=10 is shadowed
    _ => { /* Fallback */ }
}
```

**Binding Integration**
Range patterns can be bound to variables using the `@` (at) operator. This captures the matched value into a local variable while simultaneously enforcing the boundary constraints of the range pattern.

```rust theme={"dark"}
let target_value = 42;

match target_value {
    bound_var @ 0..=100 => { 
        // bound_var holds the value (42) because it falls in the range 
    }
    _ => {}
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Rust Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
