sort-const

Crates.iosort-const
lib.rssort-const
version1.0.1
created_at2025-03-03 07:40:36.987479+00
updated_at2025-03-05 07:38:17.778575+00
descriptionSort arrays and slices in const contexts.
homepagehttps://docs.rs/sort-const
repositoryhttps://github.com/Daniel-Aaron-Bloom/sort-const-rs
max_upload_size
id1575261
size19,197
(Daniel-Aaron-Bloom)

documentation

https://docs.rs/sort-const

README

sort-const

Crates.io Workflow Status

A macro for sorting arrays and slices at compile time.

Usage

Just use the const_quicksort or const_shellsort macros.

use sort_const::const_quicksort;

const fn lt(a: &u8, b: &u8) -> bool {
    *a < *b
}

const A: &[u8] = &const_quicksort!([3, 1, 2]);
const B: &[u8] = &const_quicksort!([3, 1, 2], |a, b| *a < *b);
const C: &[u8] = &const_quicksort!([3, 1, 2], lt);

assert_eq!(A, [1, 2, 3]);
assert_eq!(B, [1, 2, 3]);
assert_eq!(C, [1, 2, 3]);

For now, this crate uses a custom consty fork of arrayvec. bluss/arrayvec#294 should fix this.

License

Licensed under

Commit count: 3

cargo fmt