> ## 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 Bitwise OR

The `|` (pipe) token in Rust serves three distinct syntactical and semantic functions depending on its lexical context: as a bitwise inclusive OR operator, as an alternation delimiter in pattern matching, and as the parameter enclosure for closures.

## 1. Bitwise Inclusive OR Operator

When applied to integer or boolean types, `|` performs a bitwise inclusive OR operation. It evaluates to `1` for each bit position where at least one of the operands has a `1`.

At the type-system level, this operation is governed by the `std::ops::BitOr` trait. Types implementing this trait define the behavior of the `|` operator. The compound assignment variant, `|=`, is governed by the `std::ops::BitOrAssign` trait.

```rust theme={"dark"}
let a: u8 = 0b1010_0000;
let b: u8 = 0b0000_1111;

// Bitwise OR operation
let c: u8 = a | b; // Evaluates to 0b1010_1111
```

## 2. Pattern Alternation

In pattern matching contexts (`match` arms, `if let`, `while let`, and `let` statements), the `|` token acts as a logical OR for patterns. It allows a single execution path to respond to multiple distinct structural matches.

A strict compiler constraint applies here: if the pattern binds variables, every alternative separated by `|` must bind the exact same set of variables, and those variables must have identical types across all alternatives.

```rust theme={"dark"}
enum Status {
    Active(i32),
    Pending(i32),
    Inactive,
}

let status = Status::Active(42);

match status {
    // Alternation with structural binding
    // Both sides of the `|` must bind the variable `val` with the exact same type
    Status::Active(val) | Status::Pending(val) => println!("Value: {}", val),
    
    Status::Inactive => (),
}

let x = 2;

match x {
    // Pattern alternation matching multiple literal values
    1 | 2 | 3 => println!("Matched a low integer"),
    _ => (),
}
```

## 3. Closure Parameter Delimiter

Rust uses the `|` token to enclose the parameter list of an anonymous function (closure). This syntax replaces the parentheses `()` used in standard `fn` declarations.

The parameters between the pipes can have explicit type annotations or rely on the compiler's type inference. If a closure takes no arguments, it is denoted by two adjacent pipes `||`.

```rust theme={"dark"}
// Inferred types
let add = |a, b| a + b;

// Explicit type annotations and return type
let multiply = |a: i32, b: i32| -> i32 { 
    a * b 
};

// Zero parameters
let execute = || println!("Executed");
```

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