cmporder 0.1.1

macros for prioritized Ord/PartialOrd
Documentation
# CmpOrder


Simple Macros to implement **prioritized `Ord`/`PartialOrd`**

[![Crates.io](https://img.shields.io/crates/v/cmporder)](https://crates.io/crates/cmporder)
[![docs.rs](https://img.shields.io/docsrs/cmporder?color=blue&label=docs.rs)](https://docs.rs/cmporder)

## Examples


### `cmp_order!`


```rust
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

struct ABC {
    a: u8,
    b: u8,
}

impl Ord for ABC {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        // priority:
        // 1) a
        // 2) b%2
        // 3) b
        cmp_order!(
            self.a.cmp(&other.a),
            (self.b % 2).cmp(&(other.b % 2)),
            self.b.cmp(&other.b),
        )
    }
}

impl PartialOrd for ABC {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

let abc1 = ABC { a: 10, b: 20 };
let abc2 = ABC { a: 20, b: 10 };
let abc3 = ABC { a: 10, b: 11 };
let mut list = vec![abc1, abc2, abc3];

list.sort();
assert_eq!(list, vec![abc1, abc3, abc2]);
```

### `partial_cmp_order!`


```rust
impl PartialOrd for ABC {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        // priority:
        // 1) a
        // 2) b%2
        // 3) b
        partial_cmp_order!(
            self.a.partial_cmp(&other.a),
            Some((self.b % 2).cmp(&(other.b % 2))),
            self.b.partial_cmp(&other.b)
        )
    }
}
```