Skip to content

Expose impl_static_sorter macro? #3

Description

@overlookmotel

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions