Would you consider exposing the impl_static_sorter
macro?
With const_trait_impl
feature, it's possible to create a const impl of PartialOrd
for a user-defined type. It would then be possible use staticsort
to sort this type.
This would work:
#![feature(const_trait_impl)]
use std::cmp::Ordering;
use staticsort::{staticsort, impl_static_sorter};
#[derive(Copy, Clone, Debug, PartialEq)]
struct Foo {
inner: u32,
}
impl const PartialOrd for Foo {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(if self.inner < other.inner {
Ordering::Less
} else if self.inner > other.inner {
Ordering::Greater
} else {
Ordering::Equal
})
}
}
impl_static_sorter!(Foo);
const FOOS: [Foo; 3] = [Foo { inner: 3 }, Foo { inner: 2 }, Foo { inner: 1 }];
const FOOS_SORTED: [Foo; 3] = staticsort!(Foo, 0, 2, FOOS);
If you'd be open to this, I'd be happy to make a PR.