> ## 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 Path Pattern

A path pattern is a pattern that matches a value against a named constant, a unit struct, or a unit enum variant resolved through a module path. It evaluates to `true` if the matched value is structurally equal to the value represented by the path. Unlike identifier patterns, path patterns do not introduce new variable bindings into the local scope; they strictly perform structural equality checks against pre-existing items in the module tree.

## Syntax

A path pattern follows standard Rust path resolution syntax. It supports relative paths, absolute paths from the crate root, generic arguments, and fully qualified paths for trait items.

```text theme={"dark"}
PathPattern :
    PathExpression | QualifiedPathInExpression

PathExpression :
    ( :: | crate :: | self :: | super :: )? PathSegment ( :: PathSegment )*

PathSegment :
    Identifier ( :: GenericArgs )?

QualifiedPathInExpression :
    < Type ( as Trait )? > ( :: PathSegment )+
```

## Resolution Mechanics

The Rust compiler distinguishes between path patterns and identifier patterns based on scope resolution:

1. **Multi-segment paths:** Any pattern containing a double-colon `::` (e.g., `Module::Item`, `Option::None`, or `<T as Trait>::CONSTANT`) is unambiguously parsed as a path pattern.
2. **Single-segment paths:** If a pattern consists of a single identifier (e.g., `Item`), the compiler queries the current scope's value namespace.
   * If the identifier resolves to a constant, unit struct, or unit enum variant, it is treated as a path pattern.
   * If the identifier resolves to another item in the value namespace (such as a tuple struct, tuple enum variant, or a struct with fields), the compiler emits a compilation error (e.g., `E0532` or `E0533`), as these items require tuple or struct patterns.
   * If the identifier does *not* resolve to any item in the value namespace, it is treated as an identifier pattern and binds the matched value to a new variable.

## Resolvable Items

A path pattern must resolve to one of the following item types:

* **Constants:** Items defined via the `const` keyword.
* **Unit Enum Variants:** Variants of an `enum` that hold no data.
* **Unit Structs:** Structs defined without fields.

```rust theme={"dark"}
const THRESHOLD: i32 = 10;

#[derive(PartialEq, Eq)]
enum State {
    Halted,
    Running,
    Paused,
}

struct Sentinel;

trait DefaultState {
    const DEFAULT: State;
}

impl DefaultState for State {
    const DEFAULT: State = State::Halted;
}

fn evaluate_pattern(value: i32, state: State, sentinel: Sentinel) {
    // Path pattern resolving to a constant
    match value {
        THRESHOLD => {} 
        _ => {}
    }

    // Path patterns resolving to unit enum variants and constants
    match state {
        <State as DefaultState>::DEFAULT => {} // Fully qualified path pattern (matches Halted)
        crate::State::Running => {}            // Absolute path pattern
        State::Paused => {}                    // Relative path pattern
    }

    // Path pattern resolving to a unit struct
    match sentinel {
        Sentinel => {}
    }
}
```

## Semantics and Constraints

* **Structural Equality:** When a path pattern resolves to a constant, the pattern matching does *not* call the `PartialEq::eq` method. Executing user-defined trait methods during pattern matching would allow arbitrary code execution and side effects. Instead, the compiler relies on intrinsic *structural equality*.
* **Trait Requirements:** For a constant of a custom type to be valid in a path pattern, its type must have `#[derive(PartialEq, Eq)]`. This macro derives the hidden, compiler-internal `StructuralPartialEq` and `StructuralEq` traits, which authorize the compiler to perform a structural comparison (field-by-field) of the data.
* **Structural Match Restrictions:** If a constant contains types that do not implement the structural match traits (such as raw pointers, floating-point numbers, or types with custom, non-derived `PartialEq` implementations), the compiler will emit a structural match error.
* **Refutability:** The refutability of a path pattern depends entirely on the item it resolves to. A path pattern is **irrefutable** if it resolves to a unit struct, a variant of a single-variant enum, or a constant whose type is a singleton (a type with only one possible value, such as `()`), meaning any match against it is inherently exhaustive. It is **refutable** if it resolves to a variant of a multi-variant enum or a constant of a type with multiple possible values (such as an integer or a multi-variant enum).

<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>
