[][src]Crate ord_by_key

Provides a convenient macro for implementing Ord trait with logic specified in an inline expression

use ord_by_key::ord_eq_by_key_selector;
use core::cmp::Reverse;
// `Person` will be ordered by `last_name`, then by `first_name`, then by `age` in reverse
pub struct Person {
    pub first_name: String,
    pub last_name: String,
    pub age: usize,
use ord_by_key::ord_eq_by_key_selector;
// Container for [`&str`] which will be ordered by underlying string length
#[ord_eq_by_key_selector(|(s)| s.len())]
pub struct StrByLen<'a> (&'a str);

// Note, comparison happens just based on string length
assert!(StrByLen("Alex") > StrByLen("Bob"));
assert!(StrByLen("Alex") == StrByLen("John"));
assert!(StrByLen("Alex") < StrByLen("Michael"));

Attribute Macros


Implements Ord, PartialOrd, PartialEq and Eq for a struct.