macro_rules! scalar_callback {
($name:ident, |$info:ident, $input:ident, $output:ident| $body:block) => { ... };
}Expand description
Generates a panic-safe unsafe extern "C" scalar function callback.
The macro emits a function with signature:
unsafe extern "C" fn $name(
info: duckdb_function_info,
input: duckdb_data_chunk,
output: duckdb_vector,
)The body is wrapped in std::panic::catch_unwind. If the closure panics,
the error is reported via duckdb_scalar_function_set_error and the
function returns without unwinding across the FFI boundary.
§Parameters
$name— the name of the generated function$body— a closure with signature|info: duckdb_function_info, input: duckdb_data_chunk, output: duckdb_vector|
§Example
quack_rs::scalar_callback!(double_it, |info, input, output| {
let chunk = unsafe { quack_rs::data_chunk::DataChunk::from_raw(input) };
let reader = unsafe { chunk.reader(0) }; // once per chunk, not per row
let mut writer = unsafe { quack_rs::vector::VectorWriter::from_vector(output) };
for row in 0..chunk.size() {
let val = unsafe { reader.read_i64(row) };
unsafe { writer.write_i64(row, val * 2) };
}
});