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

The `>` (greater than) operator is a binary comparison operator that evaluates whether the left-hand operand is strictly greater than the right-hand operand, returning a `bool`. In Rust, this operator is syntactic sugar for the `gt` method provided by the `std::cmp::PartialOrd` trait.

## Syntax

```rust theme={"dark"}
left_operand > right_operand
```

## Trait Mechanics

When the compiler encounters the `>` operator, it translates the expression into a fully qualified function call to the `PartialOrd` trait. The expression `a > b` desugars to `std::cmp::PartialOrd::gt(&a, &b)`.

It is not strictly equivalent to the method call syntax `a.gt(&b)`. The method call syntax is subject to dot-operator method resolution rules (such as auto-referencing and auto-dereferencing) and could potentially resolve to an inherent method named `gt` on the type rather than the `PartialOrd` trait method. The `>` operator bypasses this ambiguity by directly invoking the trait.

```rust theme={"dark"}
pub trait PartialOrd<Rhs = Self>: PartialEq<Rhs> {
    fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;

    // The `>` operator maps to this provided method
    fn gt(&self, other: &Rhs) -> bool {
        matches!(self.partial_cmp(other), Some(Ordering::Greater))
    }
}
```

To use the `>` operator, the type of the left operand must implement `PartialOrd<Rhs>` where `Rhs` is the type of the right operand. Because `PartialOrd` requires `PartialEq` as a supertrait, types compared with `>` must also support equality comparisons.

## Evaluation Rules

The behavior of the `>` operator depends on the underlying type implementation of `partial_cmp`:

* **Integers:** Performs standard mathematical comparison.
* **Floating-Point Numbers (`f32`, `f64`):** Adheres to IEEE 754 standards. Because floating-point numbers only implement `PartialOrd` and not `Ord`, comparisons involving `NaN` (Not-a-Number) will always evaluate to `false`, as `NaN` is unordered relative to any value, including itself.
* **Characters and Strings:** Performs lexicographical comparison based on underlying Unicode scalar values.
* **Compound Types (Tuples, Arrays, Slices):** Evaluates lexicographically from left to right. The operator compares elements at corresponding indices. If it finds a strictly greater element, it returns `true`. If the elements are equal, it proceeds to the next index. For sequences of unequal length (such as slices or strings) where the shorter sequence is a prefix of the longer sequence, the longer sequence is considered greater based on its length.
* **Structs and Enums:** If `#[derive(PartialOrd)]` is applied, structs are compared lexicographically top-to-bottom based on field declaration order. Enums are compared based on discriminant order (top-to-bottom), followed by their payload.

## Mechanical Demonstration

```rust theme={"dark"}
// Primitive numeric evaluation
let int_eval: bool = 10_i32 > 5_i32; // true

// Floating-point evaluation with NaN
let float_eval: bool = f64::NAN > 5.0; // false

// Lexicographical tuple evaluation
// Compares index 0 (2 == 2), then index 1 (3 > 1)
let tuple_eval: bool = (2, 3) > (2, 1); // true

// Lexicographical slice evaluation with length fallback
// The shorter slice is a prefix, so the longer slice is greater
let slice_eval: bool = [1, 2, 3].as_slice() > [1, 2].as_slice(); // true

// Explicit trait method invocation (compiler translation)
let explicit_eval: bool = std::cmp::PartialOrd::gt(&10_i32, &5_i32); // true
```

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