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

`i32` is a primitive, fixed-size data type in Rust representing a 32-bit signed integer. It occupies exactly 4 bytes of memory and encodes values using two's complement representation, allowing it to store both positive and negative whole numbers.

## Technical Specifications

* **Memory Size:** 32 bits (4 bytes)
* **Minimum Value (`i32::MIN`):** -2,147,483,648 ($-2^{31}$)
* **Maximum Value (`i32::MAX`):** 2,147,483,647 ($2^{31} - 1$)
* **Type Inference:** The Rust compiler (`rustc`) defaults to `i32` for any unannotated integer literal unless constrained by the surrounding type context.

## Syntax and Instantiation

Values of type `i32` can be declared using explicit type annotation, literal suffixes, or implicit type inference.

```rust theme={"dark"}
// Explicit type annotation
let explicit_int: i32 = 42;

// Literal type suffix
let suffixed_int = 42_i32;

// Implicit inference (defaults to i32)
let inferred_int = 42; 

// Visual separators (underscores are ignored by the compiler)
let large_int: i32 = 1_000_000;
```

`i32` supports standard numeric literal prefixes for different bases:

```rust theme={"dark"}
let hex_val: i32 = 0x2A;        // Hexadecimal (42 in decimal)
let octal_val: i32 = 0o52;      // Octal (42 in decimal)
let binary_val: i32 = 0b101010; // Binary (42 in decimal)
```

## Overflow Behavior

Rust handles `i32` arithmetic overflow differently depending on the compilation profile:

* **Debug mode (`cargo build`):** Integer operations that exceed the `i32` bounds trigger a runtime panic.
* **Release mode (`cargo build --release`):** The compiler performs standard two's complement wrapping. Values wrap *through* the boundary rather than stopping at it (e.g., `i32::MAX + 1` results in `i32::MIN`, and `i32::MAX + 2` results in `i32::MIN + 1`), without panicking.

To explicitly control overflow behavior regardless of the build profile, the `i32` primitive provides standard library methods:

```rust theme={"dark"}
let max = i32::MAX;

// Returns an Option<i32>, evaluating to None if overflow occurs
let checked = max.checked_add(1); 

// Wraps through the boundary to i32::MIN (-2147483648)
let wrapped = max.wrapping_add(1); 

// Caps at the boundary, remaining at i32::MAX (2147483647)
let saturated = max.saturating_add(1); 

// Returns a tuple (i32, bool) indicating the wrapped value and an overflow flag
let (overflowing, did_overflow) = max.overflowing_add(1);
```

## Memory Layout and Casting

`i32` implements the `Copy` trait, meaning reassignments perform a bitwise duplication of the value rather than moving ownership. The memory location of an `i32` is determined by its allocation context: it is stored on the stack when declared as a local variable, but resides on the heap when owned by a heap-allocated collection or smart pointer (e.g., `Vec<i32>` or `Box<i32>`).

Casting `i32` to other numeric types requires the explicit `as` keyword. Casting to a smaller integer type (e.g., `i16` or `i8`) truncates the higher-order bits.

```rust theme={"dark"}
let base_val: i32 = 300;

// Lossless cast to a larger type
let larger_val: i64 = base_val as i64; 

// Truncating cast to a smaller type (300 becomes 44 in i8)
let truncated_val: i8 = base_val as i8; 
```

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