Skip to main content
Trait for comparing types that form a partialorder. The lt, le, gt, and ge methods of this trait can be called using the “, and >= operators, respectively. PartialOrd is not derivable, but can be implemented manually

Signature

Implementing PartialOrd

Here’s how to implement PartialOrd for a custom type. This example implements comparison operations for a 2D point where points are compared based on their squared Euclidean distance from the origin (0,0):
Note that only the lt method needs to be implemented. The other comparison operations (le, gt, ge) are automatically derived from lt. However, you can override them for better performance if needed.

Trait functions

lt

Tests less than (for self and other) and is used by the `(lhs: T, rhs: T) -> bool

gt

Tests greater than (for self and other) and is used by the > operator.

Signature

Examples

le

Tests greater than or equal to (for self and other) and is used by the >= operator.

Signature

Examples