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

The wildcard pattern (`_`) is an irrefutable pattern that matches any value without binding it to an identifier. It instructs the compiler to explicitly discard the matched data, satisfying pattern exhaustiveness checks while preventing "unused variable" warnings.

**Binding, Ownership, and Drop Semantics**
Unlike named variables or variables prefixed with an underscore (e.g., `_var`), the standalone wildcard `_` never creates a binding. Because no binding occurs, the wildcard pattern does not move, consume, or take ownership of the matched value.

```rust theme={"dark"}
let s = String::from("Rust");
let _ = s; // Matches 's' but does not bind or move it
println!("{}", s); // Valid: 's' is still accessible
```

Conversely, an identifier prefixed with an underscore acts as a standard binding and will trigger move semantics for non-`Copy` types:

```rust theme={"dark"}
let s = String::from("Rust");
let _s = s; // Binds and moves 's'
// println!("{}", s); // Compiler error: value borrowed here after move
```

A critical mechanical consequence of `_` not creating a binding is its effect on the drop semantics of temporary values. When a temporary expression is assigned to a wildcard, the value is dropped *immediately* at the end of the statement. In contrast, assigning a temporary to a named binding (even one prefixed with an underscore) extends the value's lifetime to the end of the enclosing scope. This distinction is a common footgun in RAII (Resource Acquisition Is Initialization) patterns, such as managing lock guards.

```rust theme={"dark"}
use std::sync::Mutex;

let m = Mutex::new(0);

// The temporary MutexGuard is dropped IMMEDIATELY at the semicolon.
// The mutex is unlocked before the next line executes.
let _ = m.lock().unwrap();

// The temporary MutexGuard is bound to `_guard` and lives until the end of the scope.
// The mutex remains locked for subsequent operations.
let _guard = m.lock().unwrap();
```

**Structural Destructuring**
The wildcard pattern can be nested within compound patterns to selectively ignore specific elements of tuples, arrays, enums, or structs during destructuring.

*Tuples and Arrays:*

```rust theme={"dark"}
let coordinate = (10, 20, 30);
let (x, _, z) = coordinate; // Ignores the second element
```

*Enums:*

```rust theme={"dark"}
let result: Result<i32, String> = Err(String::from("Error"));
match result {
    Ok(val) => println!("Value: {}", val),
    Err(_) => println!("Error ignored"), // Matches the Err variant but ignores the inner String
}
```

*Structs:*

```rust theme={"dark"}
struct Point { x: i32, y: i32, z: i32 }
let p = Point { x: 0, y: 1, z: 2 };
let Point { x, y: _, z } = p; // Ignores the 'y' field during destructuring
```

**Exhaustiveness in `match` Expressions**
Because `_` is irrefutable (it cannot fail to match), it functions as a universal catch-all. When placed as the final arm of a `match` expression, it guarantees that all possible variants of a type are accounted for, satisfying the compiler's strict exhaustiveness requirements.

```rust theme={"dark"}
let value = 5u8;
match value {
    1 => println!("One"),
    2 => println!("Two"),
    _ => println!("Catch-all"), // Matches 0, and 3 through 255
}
```

**Function and Closure Parameters**
The wildcard can replace parameter names in function, trait method, or closure signatures. This indicates that an argument is structurally required by the type signature but is intentionally ignored in the implementation scope.

```rust theme={"dark"}
fn process_data(data: i32, _: bool) {
    // The boolean argument must be passed by the caller, 
    // but it is not bound to an identifier in this scope.
}
```

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