macro_rules! cast_callback {
($name:ident, |$info:ident, $count:ident, $input:ident, $output:ident| $body:block) => { ... };
}Expand description
Generates a panic-safe unsafe extern "C" cast callback.
Emits
unsafe extern "C" fn $name(info: duckdb_function_info, count: idx_t, input: duckdb_vector, output: duckdb_vector) -> bool.
The body must evaluate to bool — true when every row converted.
A panic is reported through duckdb_cast_function_set_error and the
generated function returns false. In a regular CAST that fails the
query with the panic message, and in DuckDB’s internal value casts it
makes DuckDB throw. In a TRY_CAST, DuckDB ignores the return
value (see CastFn), so the generated function also
sets every row of the chunk to NULL through
duckdb_cast_function_set_row_error: whatever the body wrote before it
panicked cannot be trusted, and a row it never reached would otherwise keep
a stale value.
A body that returns false without panicking is passed through untouched;
in TRY_CAST mode it must null its own failed rows. In a regular CAST, a
body that returns false without setting a message fails the query with
CAST_FAILED_WITHOUT_MESSAGE rather than an empty Conversion Error: .
§Example
quack_rs::cast_callback!(my_cast, |info, count, input, output| {
let _ = (count, input, output);
true
});