compile_time_sort
This small crate provides functions for sorting arrays and slices of primitives in const
contexts.
Arrays and slices of bool
s, u8
s, and i8
s are sorted with counting sort while arrays of other types
are sorted with quicksort.
This implementation is usable on Rust version 1.59.0,
before the const_trait_impl
feature is stabilized.
This means that it unfortunately can not be generic,
and so there are separate functions for every primitive type.
Functions with the naming convention into_sorted_*_array
take an array by value,
and functions with the naming convention sort_*_slice
take a mutable reference to a slice.
The functions that sort slices by reference are only available on Rust versions 1.83 and above.
Examples
Sort an array by value:
use into_sorted_i32_array;
const ARRAY: = ;
const SORTED_ARRAY: = into_sorted_i32_array;
assert_eq!;
Sort by reference:
use sort_i32_slice;
const SORTED_ARRAY: = ;
assert_eq!;