This crate provides the #[derive(SortBy)]
derive macro that implements the traits Ord
, PartialOrd
, Eq
, PartialEq
and Hash
on structs that can't automatically derive those traits because they contain unorderable fields such as f32
.
Fields that must be included in the sorting are explicitly marked with the attribute #[sort_by]
, unmarked fields will be ignored.
As with #[derive(Ord)]
and #[derive(PartialEq)]
, order of sorting is the same as the order of appearance of fields.
```rust
struct Toto { #[sortby] a: u16, #[sortby] c: u32, b: f32 } ```
expands to
```rust struct Toto { a: u16, c: u32, b: f32 }
impl std::hash::Hash for Toto {
fn hash
From there sort
can be called on a Vec<Toto>
.
Only structs with named fields are supported.