Expand description
§partial-cmp-derive
A procedural macro crate for deriving PartialOrd and Ord with fine-grained
control over field comparison behavior.
§Features
- Skip fields: Use
#[ord(skip)]to exclude fields from comparison - Sort order: Use
#[ord(order = "asc")]or#[ord(order = "desc")]per field - Explicit ordering: Use
#[ord(by = [field1(desc), field2(asc)])]at struct level - Field priority: Use
#[ord(priority = N)]for implicit ordering (lower = first) - Custom comparators: Use
#[ord(compare_with = "path::to::fn")] - Reverse all: Use
#[ord(reverse)]at struct level to reverse entire comparison - Enum ranking: Use
#[ord(rank = N)]to control variant ordering - Option handling: Use
#[ord(none_order = "first")]or"last"
§Example
use partial_cmp_derive::PartialCmpDerive;
#[derive(PartialEq, Eq, PartialCmpDerive)]
struct Player {
#[ord(skip)]
id: u64,
#[ord(order = "asc")]
name: String,
#[ord(order = "desc")]
score: u32,
}This generates PartialOrd and Ord implementations that compare name
ascending, then score descending, while ignoring id entirely.
Derive Macros§
- Partial
CmpDerive - Derives
PartialOrdandOrdwith customizable field comparison behavior.