baml._rust_sort

Sorts a primitive array (`int`/`bigint`/`string`/`float`) in place by its natural order and returns it (the same array object — no copy). Total and infallible for every supported element type — `float` uses BAML's total float order, which covers NaN, so it never throws. Only reached from `Sortable.sort`'s primitive fast path (guarded by `_is_primitive_array`), where the element type is known to be one of these — other element types use `sort_by`.

Reference version

Signature

function baml._rust_sort<A>(arr: A) -> A throws never

Sorts a primitive array (int/bigint/string/float) in place by its natural order and returns it (the same array object — no copy). Total and infallible for every supported element type — float uses BAML's total float order, which covers NaN, so it never throws. Only reached from Sortable.sort's primitive fast path (guarded by _is_primitive_array), where the element type is known to be one of these — other element types use sort_by.

arr is typed as a bare generic (A, not T[] with T extends baml.ops.Compare): the native-glue codegen passes generic parameters as raw values, which is what lets the implementation sort the receiver's backing storage in place and return the receiver itself — a T[]-typed parameter would be deconstructed to a slice and re-allocated on return. The may_yield directive is likewise glue-shaping only (raw receiver + error channel); the comparator is pure Rust and never yields to BAML.

Source:<builtin>/baml/sortable.bamlbytes 3765–3836