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

Operators in Rust are symbolic tokens that instruct the compiler to perform specific mathematical, logical, relational, or bitwise computations. Unlike many systems programming languages, Rust implements most operators as syntactic sugar for trait methods defined in the `std::ops` and `std::cmp` modules. This architecture allows operators to be overloaded for custom types by implementing the corresponding traits.

## Arithmetic Operators

Arithmetic operators perform standard mathematical computations and map directly to traits in `std::ops`. For integer types, if an operation overflows in debug mode, Rust will panic; in release mode, it performs two's complement wrapping. Floating-point types (`f32`, `f64`) follow IEEE 754 rules and will evaluate to infinity (`inf` or `-inf`) upon overflow, without panicking or wrapping in either debug or release mode.

* `+` : Addition (`std::ops::Add`)
* `-` : Subtraction (`std::ops::Sub`)
* `*` : Multiplication (`std::ops::Mul`)
* `/` : Division (`std::ops::Div`)
* `%` : Remainder (`std::ops::Rem`)
* `-` : Negation (`std::ops::Neg`)

```rust theme={"dark"}
let a = 10_i32 + 5_i32;  // Evaluated as 10_i32.add(5_i32)
let b = 10_i32 - 5_i32;  // Evaluated as 10_i32.sub(5_i32)
let c = 10_i32 * 5_i32;  // Evaluated as 10_i32.mul(5_i32)
let d = 10_i32 / 5_i32;  // Evaluated as 10_i32.div(5_i32)
let e = 10_i32 % 5_i32;  // Evaluated as 10_i32.rem(5_i32)
let f = -a;              // Evaluated as a.neg()

let g = 1e308_f64 * 10.0; // Evaluated as inf (IEEE 754 overflow)
```

## Bitwise and Eager Logical Operators

Bitwise operators manipulate the individual bits of integer types. Additionally, the `&` and `|` operators are implemented for `bool` types to perform eager (non-short-circuiting) logical evaluation. They map to traits in `std::ops`. The `!` operator is overloaded to function as a bitwise NOT when applied to integers.

* `&` : Bitwise AND / Eager Logical AND (`std::ops::BitAnd`)
* `|` : Bitwise OR / Eager Logical OR (`std::ops::BitOr`)
* `^` : Bitwise XOR (`std::ops::BitXor`)
* `!` : Bitwise NOT (`std::ops::Not`)
* `<<` : Left Shift (`std::ops::Shl`)
* `>>` : Right Shift (`std::ops::Shr`)

```rust theme={"dark"}
let and_val = 0b1010_u8 & 0b1100_u8; // Evaluated as 0b1010_u8.bitand(0b1100_u8)
let or_val  = 0b1010_u8 | 0b1100_u8; // Evaluated as 0b1010_u8.bitor(0b1100_u8)
let xor_val = 0b1010_u8 ^ 0b1100_u8; // Evaluated as 0b1010_u8.bitxor(0b1100_u8)
let not_val = !0b1010_u8;            // Evaluated as 0b1010_u8.not()
let shl_val = 0b1010_u8 << 2_u8;     // Evaluated as 0b1010_u8.shl(2_u8)
let shr_val = 0b1010_u8 >> 2_u8;     // Evaluated as 0b1010_u8.shr(2_u8)

// Eager logical evaluation (both sides are evaluated regardless of the left side's value)
let eager_and = false & true;        // Evaluated as false.bitand(true)
let eager_or  = true | false;        // Evaluated as true.bitor(false)
```

## Logical Operators

Logical operators evaluate boolean expressions. The `&&` and `||` operators utilize short-circuit evaluation. Because short-circuiting requires controlling control flow, `&&` and `||` **cannot** be overloaded and do not have backing traits. The `!` operator functions as a logical NOT when applied to booleans.

* `&&` : Logical AND (Short-circuiting)
* `||` : Logical OR (Short-circuiting)
* `!` : Logical NOT (`std::ops::Not`)

```rust theme={"dark"}
let is_true = (true && false) || true;
let is_false = !is_true; // Evaluated as is_true.not()
```

## Comparison (Relational) Operators

Comparison operators evaluate the relationship between two values, returning a boolean. They map to traits in `std::cmp`.

* `==` : Equal to (`std::cmp::PartialEq`)
* `!=` : Not equal to (`std::cmp::PartialEq`)
* `<` : Less than (`std::cmp::PartialOrd`)
* `>` : Greater than (`std::cmp::PartialOrd`)
* `<=` : Less than or equal to (`std::cmp::PartialOrd`)
* `>=` : Greater than or equal to (`std::cmp::PartialOrd`)

```rust theme={"dark"}
let eq = 5_i32 == 5_i32; // Evaluated via PartialEq::eq
let ne = 5_i32 != 5_i32; // Evaluated via PartialEq::ne
let lt = 5_i32 < 10_i32; // Evaluated via PartialOrd::lt
```

## Assignment and Compound Assignment Operators

The basic assignment operator (`=`) binds a value to a memory location or updates a mutable variable. Compound assignment operators combine an arithmetic or bitwise operation with assignment. Compound operators map to traits in `std::ops` suffixed with `Assign`. They mutate the left-hand operand in place and do not return a value (they evaluate to the unit type `()`).

* `=` : Basic Assignment
* `+=`, `-=`, `*=`, `/=`, `%=` : Arithmetic Compound Assignment
* `&=`, `|=`, `^=`, `<<=`, `>>=` : Bitwise Compound Assignment

```rust theme={"dark"}
let mut x;
x = 5_i32;   // Basic assignment

x += 5_i32;  // Evaluated as x.add_assign(5_i32)
x <<= 1_i32; // Evaluated as x.shl_assign(1_i32)
```

## Type, Memory, and Access Operators

Rust includes specific operators for memory management, pointer manipulation, collection access, and type conversion.

* `&` : Shared borrow / Reference creation
* `&mut` : Mutable borrow / Mutable reference creation
* `*` : Dereference (`std::ops::Deref` and `std::ops::DerefMut`)
* `[]` : Array/Slice indexing (`std::ops::Index` and `std::ops::IndexMut`)
* `as` : Safe primitive type casting

```rust theme={"dark"}
let val = 10;
let ref_val = &val;         // Shared reference

let mut mut_val = 20;       // Must be declared mutable to borrow mutably
let mut_ref = &mut mut_val; // Mutable reference

let deref_val = *ref_val;   // Dereferencing

let arr = [10, 20, 30];
let item = arr[1];          // Evaluated via Index::index

let float_val = 10 as f64;  // Type cast
```

## Control Flow and Structural Operators

These operators handle structural generation or control flow propagation at the syntax level.

* `?` : Error propagation operator. Unwraps `Result`/`Option` or returns early on `Err`/`None` (`std::ops::Try`).
* `..` : Exclusive range (`std::ops::Range`)
* `..=` : Inclusive range (`std::ops::RangeInclusive`)

```rust theme={"dark"}
fn some_fallible_function() -> Result<i32, &'static str> {
    Ok(42)
}

fn main() -> Result<(), &'static str> {
    let range_ex = 0..5;   // 0, 1, 2, 3, 4
    let range_in = 0..=5;  // 0, 1, 2, 3, 4, 5

    // Error propagation syntax requires a compatible return type
    let result = some_fallible_function()?; 
    
    Ok(())
}
```

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