#sorting #no-alloc #const-sort

no-std sort-const

Sort arrays and slices in const contexts

2 stable releases

1.0.1 Mar 5, 2025
1.0.0 Mar 3, 2025

#2387 in Algorithms

Download history 323/week @ 2025-10-13 318/week @ 2025-10-20 293/week @ 2025-10-27 126/week @ 2025-11-03 361/week @ 2025-11-10 247/week @ 2025-11-17 437/week @ 2025-11-24 449/week @ 2025-12-01 427/week @ 2025-12-08 340/week @ 2025-12-15 318/week @ 2025-12-22 114/week @ 2025-12-29 70/week @ 2026-01-05 122/week @ 2026-01-12 308/week @ 2026-01-19 311/week @ 2026-01-26

820 downloads per month
Used in 2 crates

MIT/Apache

17KB
255 lines

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

Dependencies

~640KB