6161 **/
6262pub fn sort_extended <T , let N : u32 >(
6363 input : [T ; N ],
64- sortfn : fn (T , T ) -> bool ,
64+ sortfn : unconstrained fn (T , T ) -> bool ,
6565 sortfn_assert : fn (T , T ) -> (),
6666) -> [T ; N ]
6767where
@@ -82,7 +82,7 @@ pub struct SortResult<T, let N: u32> {
8282}
8383pub fn sort_advanced <T , let N : u32 >(
8484 input : [T ; N ],
85- sortfn : fn (T , T ) -> bool ,
85+ sortfn : unconstrained fn (T , T ) -> bool ,
8686 sortfn_assert : fn (T , T ) -> (),
8787) -> SortResult <T , N >
8888where
@@ -107,6 +107,10 @@ mod test {
107107 a <= b
108108 }
109109
110+ unconstrained fn __sort_u32 (a : u32 , b : u32 ) -> bool {
111+ a <= b
112+ }
113+
110114 // unconditional_lt will cost fewer constraints than the `<=` operator
111115 // as we do not need to constrain the case where `a > b`, and assign a boolean variable to the result
112116 fn unconditional_lt (_a : u32 , _b : u32 ) {
@@ -141,7 +145,7 @@ mod test {
141145 fn test_sort_extended () {
142146 let mut arr : [u32 ; 7 ] = [3 , 6 , 8 , 10 , 1 , 2 , 1 ];
143147
144- let sorted = sort_extended (arr , sort_u32 , unconditional_lt );
148+ let sorted = sort_extended (arr , __sort_u32 , unconditional_lt );
145149
146150 let expected : [u32 ; 7 ] = [1 , 1 , 2 , 3 , 6 , 8 , 10 ];
147151 assert (sorted == expected );
0 commit comments