> ## 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 Less Than

The `<` (less-than) operator is a binary comparison operator that evaluates whether the left-hand operand is strictly less than the right-hand operand, returning a `bool`.

At the compiler level, the `<` operator is syntactic sugar for the `lt` method provided by the `std::cmp::PartialOrd` trait.

```rust theme={"dark"}
let a = 1;
let b = 2;

// Standard syntax
let result = a < b;

// Desugared equivalent
let result = std::cmp::PartialOrd::lt(&a, &b);
```

## Trait Implementation

To use the `<` operator with a specific type, that type must implement `PartialOrd`. Because `PartialOrd` has a supertrait bound on `PartialEq`, any type supporting `<` must also support the `==` operator.

```rust theme={"dark"}
use std::cmp::Ordering;

pub trait PartialOrd<Rhs = Self>: PartialEq<Rhs>
where
    Rhs: ?Sized,
{
    fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;

    // The `<` operator directly invokes this provided method
    #[inline]
    fn lt(&self, other: &Rhs) -> bool {
        matches!(self.partial_cmp(other), Some(Ordering::Less))
    }
}
```

## Evaluation Mechanics

1. **Delegation to `partial_cmp`**: The default implementation of `lt` calls `partial_cmp`, which returns an `Option<std::cmp::Ordering>`.
2. **Strict Evaluation**: The `<` operator evaluates to `true` *only* if `partial_cmp` returns `Some(Ordering::Less)`.
3. **Incomparable Values**: If `partial_cmp` returns `None` (which occurs with incomparable values, such as floating-point `NaN`), the `<` operator evaluates to `false`.
4. **Borrowing**: The operator implicitly takes immutable references to both operands (`&self` and `&Rhs`). It does not consume or move the values being compared.

## Type Constraints

Rust enforces strict type safety during comparison. The `<` operator does not perform implicit type coercion. Both operands must resolve to the same type, or the left-hand type must explicitly implement `PartialOrd<Rhs>` where `Rhs` is the type of the right-hand operand.

```rust theme={"dark"}
// Valid: Same types
let valid = 5_i32 < 10_i32;

// Invalid: Compilation error due to mismatched types (i32 vs f64)
// let invalid = 5_i32 < 10.0_f64; 
```

## Derivation

For custom structs and enums, the compiler can automatically generate the `<` operator logic using `#[derive(PartialOrd)]`. Because of the supertrait bound, `#[derive(PartialEq)]` is also strictly required; attempting to derive `PartialOrd` without deriving `PartialEq` results in a compilation error.

When derived:

* **Structs**: Evaluates fields lexicographically, top-to-bottom.
* **Enums**: Evaluates based on the discriminant (the declared order of variants), followed by lexicographical comparison of any data contained within the variants.

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