#ord #macro-derive #partial-ord #derive #macro

macro impartial-ord

Derives a quicker PartialOrd for types that already implement Ord

6 stable releases

1.0.5 Apr 28, 2023
1.0.4 Apr 21, 2023
1.0.1 Mar 4, 2023

#1551 in Development tools

36 downloads per month

MIT license

5KB

master CI badge crates.io badge docs.rs badge dependencies badge

Derives a quicker PartialOrd for types that already implement Ord.

// Input
#[derive(PartialEq, Eq, Ord, impartial_ord::ImpartialOrd)]
struct MyStruct;

// Output
impl PartialOrd for MyStruct {
    #[inline]
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(Ord::cmp(self, other))
    }
}

lib.rs:

#
// Input
#[derive(PartialEq, Eq, Ord, impartial_ord::ImpartialOrd)]
struct MyStruct { foo: Bar, qux: Baz, }

// Output
impl PartialOrd for MyStruct where Self: Ord {
  #[inline]
  fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
    Some(Ord::cmp(self, other))
  }
}

Dependencies

~295–740KB
~18K SLoC