#[derive(PartialCmp)]
{
// Attributes available to this derive:
#[ord]
}
Expand description
Derives PartialOrd and Ord with customizable field comparison behavior.
§Struct-Level Attributes
#[ord(reverse)]— Reverses the final comparison result#[ord(by = [field1(asc), field2(desc)])]— Explicit field comparison order#[ord(skip_ord)]— Only implementPartialOrd, notOrd
§Field-Level Attributes
#[ord(skip)]— Exclude this field from comparison. Note: When any field is skipped, onlyPartialOrdis implemented (notOrd), allowing skipped fields to contain types that don’t implementOrdorEq(likef32).#[ord(order = "asc")]or#[ord(order = "desc")]— Sort direction#[ord(priority = N)]— Comparison priority (lower = compared first)#[ord(compare_with = "path::to::fn")]— Custom comparison function#[ord(none_order = "first")]or#[ord(none_order = "last")]— Option handling
§Variant-Level Attributes (Enums)
#[ord(rank = N)]— Explicit variant ranking (lower = less than)
§Requirements
- The type must also derive or implement
PartialEq(andEqifOrdis generated) - All compared fields must implement
Ord(or providecompare_with) - Skipped fields have no trait requirements
§Example
use partial_cmp_derive::PartialCmp;
#[derive(PartialEq, Eq, PartialCmp)]
#[ord(by = [score(desc), name(asc)])]
struct Player {
id: u64, // Not compared (not in `by` list)
name: String,
score: u32,
}